我无法创建延伸android.service.notification.NotificationListenerService
NotificationListenerService没有连接到通知管理器
按https://developer.android.com/reference/android/service/notification/NotificationListenerService.html我加入以下的清单服务:
<service android:name=".NotificationListener"
android:label="@string/service_name"
android:permission="android.permission.BIND_NOTIFICATION_LISTENER_SERVICE">
<intent-filter>
<action android:name="android.service.notification.NotificationListenerService" />
</intent-filter>
</service>
我重写Service#onStartCommand
:
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
Log.d(TAG, "Got onStartCommand");
return super.onStartCommand(intent, flags, startId);
}
and NotificationListenerService#onListenerConnected
:
@Override
public void onListenerConnected() {
Log.d(TAG, "Got onListenerConnected");
}
当我运行,虽然开始明确的意图服务,我看到,onStartCommand
运行,但不是onListenerConnected
。如果我尝试运行requestInterruptionFilter(NotificationListenerService.INTERRUPTION_FILTER_NONE)
,从onStartCommand
(这是我想做的事情)我得到W/NotificationListenerService[NotificationListener]: Notification listener service not yet bound.
任何想法,为什么我没有得到onListenerConnected()
(因此不能发送requestInterruptionFilter
)?
这是关于Xperia Z1 compact的Lollipop 5.1.1。
对此有何好运? – user1163234