在安卓手机上使用Skype时,如何进行通话检测?

7

就像使用PhoneStateListener检测电话呼叫一样,在Android上我希望检测来自Skype的通话。是否有像电信电话那样的Skype监听器?请建议一些方法。


它是一个独立的应用程序并使用互联网通话,所以我想他们可能没有保留任何打开的事件进行处理。 - Neji
如果Skype没有提供任何文档,那么就会很困难,甚至可能是不可能的。你可以看看Skype的日志文件。如果你注意到通过Android广播的意图,那么这可能被用作钩子。 - Snicolas
@Snicolas 谢谢,我会去找一下。有没有通过套接字检测Skype通话的方法? - Ajit
@Ajit,我不这么认为。 - Snicolas
@Snicolas 好的。您能回答一下这个问题吗?http://stackoverflow.com/questions/22833548/differenciate-the-text-of-voice-in-android - Ajit
@Ajit,我不知道那个额外的问题。 - Snicolas
2个回答

5
感谢我的朋友Shazli,提供了一种可靠的解决方法来解决这个问题。
每当Skype通话连接时,它会弹出一个通知,在结束通话时会删除该通知。 NotificationListenerService可用于检测Skype通知。
请在清单文件中添加以下行。
<service android:name=".SkypeNotificationListenerService"
        android:label="@string/app_name"
        android:permission="android.permission.BIND_NOTIFICATION_LISTENER_SERVICE">
        <intent-filter>
            <action android:name="android.service.notification.NotificationListenerService" />
        </intent-filter>
    </service>

创建一个服务来监听通知。
public class SkypeNotificationListenerService extends NotificationListenerService {
private boolean mSkypeConnected;
private static final String TAG = "NM";
public SkypeNotificationListenerService() {
}

@Override
public int onStartCommand(Intent intent, int flags, int startId) {
    return super.onStartCommand(intent, flags, startId);
}

@Override
public void onCreate() {
    super.onCreate();
    Log.d(TAG, "Service created");
    IntentFilter filter = new IntentFilter();
    filter.addAction("com.example.NOTIFICATION_LISTENER");
    LocalBroadcastManager.getInstance(this)
            .registerReceiver(nlServiceReceiver, filter);
}

@Override
public void onDestroy() {
    super.onDestroy();
    LocalBroadcastManager.getInstance(this)
            .unregisterReceiver(nlServiceReceiver);
}

@Override
public IBinder onBind(Intent intent) {
    return super.onBind(intent);
}

@Override
public void onNotificationPosted(StatusBarNotification sbn) {
    super.onNotificationPosted(sbn);
    String packageName = sbn.getPackageName();
    Log.d(TAG, "onNotificationPosted " + packageName);
    if(packageName != null && packageName.equals("com.skype.raider")) {
        Intent intent = new Intent("com.example.NOTIFICATION_LISTENER");
        intent.putExtra("connected", true);
        LocalBroadcastManager.getInstance(this).sendBroadcast(intent);
    }
}

@Override
public void onNotificationRemoved(StatusBarNotification sbn) {
    super.onNotificationRemoved(sbn);
    String packageName = sbn.getPackageName();
    Log.d(TAG, "onNotificationRemoved " + packageName);
    if(packageName != null && packageName.equals("com.skype.raider")) {
        Intent intent = new Intent("com.example.NOTIFICATION_LISTENER");
        intent.putExtra("connected", false);
        LocalBroadcastManager.getInstance(this).sendBroadcast(intent);
    }
}

@Override
public StatusBarNotification[] getActiveNotifications() {
    return super.getActiveNotifications();
}

BroadcastReceiver nlServiceReceiver = new BroadcastReceiver() {
    @Override
    public void onReceive(Context context, Intent intent) {
        if(intent != null) {
            boolean connected = intent.getBooleanExtra("connected", false);
            Intent skypeIntent;
            skypeIntent = new Intent(Constants.SKYPE_CONNECTED);
            if(connected && !mSkypeConnected) {
                mSkypeConnected = true;
                skypeIntent.putExtra("connected", true);
            } else if(!connected) {
                mSkypeConnected = false;
                Log.d(TAG, "send broadcast disconnected");
                skypeIntent.putExtra("connected", false);
            }
            sendStickyBroadcast(skypeIntent);
        }
    }
};

2
这将把来自Skype的任何通知标记为活动呼叫,Skype可能会出于其他原因(例如聊天消息)弹出通知。您可能需要对实际通知内容进行一些启发式处理,以使其可靠(直到Skype更改这些详细信息)。 - Cumbayah
常量 Constants.SKYPE_CONNECTED 是什么? - rosu alin
只是一个定义意图操作的字符串。在我的情况下,它是"com.example.SKYPE_CONNECTED"; - Amit

-2

哥们,Skype没有像电话那样的伙伴监听器,或者其他使用Skype进行Windows或安卓工具通话的方式。最好努力工作并用更加深入的方式来在不同主题上进行定位。


你在这里想表达什么? - Mikkel

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接