NotificationListenerService未创建

时间:2017-12-23 12:16:29

标签: android notifications kotlin

也许是个愚蠢的问题,但我已经花了很多时间在这上面。 我有我的Kotlin听众:

package pl.bmideas.michal.bmnotifier

public class MyNotificationListener : NotificationListenerService() {


    private var apiService :BackendApi? = null;

    override fun onCreate() {
        Log.i("MyNotificationListener" , "Creating NotificationListenerService service")
        super.onCreate()
        (.........SOMETHING ELSE..............)
    }


    override fun onDestroy() {
        super.onDestroy()
        Log.i(TAG, "DESTROING")
        (.........SOMETHING ELSE..............)
    }

    override fun onNotificationRemoved(sbn: StatusBarNotification) {
        val sbnInfo = StatusBarNotificationExtended(sbn)
        Log.i(TAG, "REMOVED")
    }

    override fun onNotificationPosted(sbn: StatusBarNotification) {
        Log.i(TAG, "RECIVED`")
        (.........SOMETHING ELSE..............)
    }
    companion object {
       var TAG = "MyNotificationListener"
    }


}

我的配置看起来像这样:

<service
            android:enabled="true"
            android:name="pl.bmideas.michal.bmnotifier.MyNotificationListener"
            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>

我没有在Activity中做任何特别的事情。

是的 - 我已经检查了安全选项,我的应用可以访问通知。

是的 - 我已尝试通过点指向服务而不是完整包

在logcat中,我只能看到:

12-23 12:56:54.989 889-889/? V/NotificationListeners: enabling notification listener for 0:  
ComponentInfo{pl.bmideas.michal.bmnotifier/pl.bmideas.michal.bmnotifier.MyNotificationListener}

我无法获得实例,除非我将在活动中竞标这项服务wchich创建服务但仍然没有在logcat中获得有关通知的信息。

你们可以帮忙吗?

1 个答案:

答案 0 :(得分:0)

冬青.... 在将此代码重写为纯Java后,它可以工作.....但为什么呢?

相关问题