小编gra*_*att的帖子

Android NotificationListenerService onNotificationPosted触发两次

我收听WhatsApp Messages等通知.

但每次通知都会在NotificationListenerService中触发两次.

有谁知道这个问题?

这是AndroidManifest.xml的一个片段:

<service android:name=".NotifyService"
            android:label="WhatsNotify"
            android:permission="android.permission.BIND_NOTIFICATION_LISTENER_SERVICE">
    <intent-filter>
                <action android:name="android.service.notification.NotificationListenerService"></action>
    </intent-filter>
</service>
Run Code Online (Sandbox Code Playgroud)

在NotificationListenerService类中:

public class NotifyService extends NotificationListenerService {

    @Override
    public void onNotificationPosted(StatusBarNotification sbn) {
        Log.i("NotifyService", "got notification");
    }
}
Run Code Online (Sandbox Code Playgroud)

编辑:两者StatusBarNotification的属性:

第一次通知:

0|com.whatsapp|1|xxxxxxxxxx@s.whatsapp.net|10073

第二次通知:

0|com.whatsapp|1|null|10073

android android-notifications android-notification-bar

6
推荐指数
1
解决办法
3753
查看次数