android中的Skype调用检测

时间:2014-04-07 05:51:33

标签: android skype

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

2 个答案:

答案 0 :(得分:4)

感谢我的朋友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);
        }
    }
};

答案 1 :(得分:-1)

没有兄弟他们不喜欢skype的电话或其他方式使用skype for windows或android工具更好地在不同的主题上工作硬盘和码的方式。