我無法創建延伸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