android中的Skype调用检测

Aji*_*jit 6 android skype

就像使用phoneStateListener进行电话呼叫检测一样,我想在android中检测来自Skype的呼叫.是否有Skype的听众,如电话呼叫.请提出一些建议.

Ami*_*mit 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>
Run Code Online (Sandbox Code Playgroud)

创建一个服务来监听通知。

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);
        }
    }
};
Run Code Online (Sandbox Code Playgroud)

  • 这会将来自 Skype 的任何通知标记为活动呼叫,Skype 可能会出于其他原因(例如聊天消息)发布通知。您可能需要对实际通知内容进行一些启发才能使其可靠(直到 Skype 更改这些详细信息)。 (2认同)

小智 -2

不,兄弟,他们不是 Skype 的好友监听器,例如电话呼叫或其他方式使用 Skype for Windows 或 Android 工具,更好地努力工作层和院子方式来定位不同的主题。