就像使用PhoneStateListener检测电话呼叫一样,在Android上我希望检测来自Skype的通话。是否有像电信电话那样的Skype监听器?请建议一些方法。
就像使用PhoneStateListener检测电话呼叫一样,在Android上我希望检测来自Skype的通话。是否有像电信电话那样的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);
}
}
};
哥们,Skype没有像电话那样的伙伴监听器,或者其他使用Skype进行Windows或安卓工具通话的方式。最好努力工作并用更加深入的方式来在不同主题上进行定位。