Android中Skype的呼叫检测 [英] Call Detection for skype in android

查看:82
本文介绍了Android中Skype的呼叫检测的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

就像使用phoneStateListener进行电话呼叫检测一样,我想在Android中检测来自Skype的呼叫.有像电话通话那样的Skype听众吗? 请提出一些建议.

Like the telephony call detection using phoneStateListener , I want to detect the call from Skype in android. Is there any listener for Skype like for telephony call. Please suggest some way.

推荐答案

感谢我的朋友Shazli,有一个可靠的解决方法来解决此问题.

Thanks to my friend Shazli, There is a reliable workaround to solve this issue.

每当连接Skype呼叫时,它都会发出通知,并在结束通话时将其删除. NotificationListenerService可用于检测Skype通知.

Whenever skype call gets connected it puts up a notification and on ending the call it removes the notification. NotificationListenerService can be used to detect the skype notification.

在清单文件中添加以下行.

Add below lines in the manifest file.

<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>

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

Create a service to listen the notifications.

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);
        }
    }
};

这篇关于Android中Skype的呼叫检测的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆