2015年8月18日火曜日

NotificationListenerServiceに関する実験メモ

NotificationListenerServiceに関する実験メモ

【1】bindについて
NotificationListenerServiceは、Serviceであるため、まさにそのとおりに使えるのではないかという仮説を立てて、
1.Activityとbindで結ぶ
2.データベースの管理
3.NotificationListenerServiceとしての本来機能
の3個を、この順番で、実行をさせてみた。
上位2個までは順に順調に実行が完了していった。
本体の「設定」>「通知へのアクセス」>本アプリの選択したあと、通知(Notification)を受け取るようにしてみたところ、次のようなエラーが出た。

W/Parcel﹕ **** enforceInterface() expected 'android.os.IMessenger' but read 'android.service.notification.INotificationListener' W/Binder﹕ Caught a RuntimeException from the binder stub implementation. java.lang.SecurityException: Binder invocation to an incorrect interface at android.os.Parcel.nativeEnforceInterface(Native Method) at android.os.Parcel.enforceInterface(Parcel.java:451) at android.os.IMessenger$Stub.onTransact(IMessenger.java:48) at android.os.Binder.execTransact(Binder.java:404) at dalvik.system.NativeStart.run(Native Method)

残念なことに、私には詳細を調べる能力や気力はありません。
NotificationListenerServiceは、本体設定>「通知へのアクセス」の設定が行われた直後に、本来機能として「何か」とbindします。
しかしながら、上記実験プログラムでは、NotificationListenerServiceは、一番最初にActivityとbindしてしまっているため、上記エラーが発生したものと推測します。

推測ですが、NotificationListenerServiceは、「Avtivityとのbind」との共存はできないのかもです。

【2】他のアプリからのIntent
他のアプリからIntentで、NotificationListenerServiceにアクセスしようとすると、クラッシュする。
6736-6736/jp.androyer.vivitovib E/AndroidRuntime﹕ FATAL EXCEPTION: main
    Process: jp.androyer.vivitovib, PID: 6736
    java.lang.SecurityException: Not allowed to start service Intent { flg=0x20000000 cmp=jp.Androyer.NotificationLauncher/.NService (has extras) } without permission android.permission.BIND_NOTIFICATION_LISTENER_SERVICE
            at android.app.ContextImpl.startServiceCommon(ContextImpl.java:1571)
            at android.app.ContextImpl.startService(ContextImpl.java:1548)
            at android.content.ContextWrapper.startService(ContextWrapper.java:495)
            at jp.androyer.vivitovib.Nippon$exportList.onPostExecute(Nippon.java:651)
            at jp.androyer.vivitovib.Nippon$exportList.onPostExecute(Nippon.java:638)
            at android.os.AsyncTask.finish(AsyncTask.java:632)
            at android.os.AsyncTask.access$600(AsyncTask.java:177)
            at android.os.AsyncTask$InternalHandler.handleMessage(AsyncTask.java:645)
            at android.os.Handler.dispatchMessage(Handler.java:102)
            at android.os.Looper.loop(Looper.java:149)
            at android.app.ActivityThread.main(ActivityThread.java:5257)
            at java.lang.reflect.Method.invokeNative(Native Method)
            at java.lang.reflect.Method.invoke(Method.java:515)
            at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:788)
            at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:604)
            at dalvik.system.NativeStart.main(Native Method)

クラッシュを引き起こさせるとは、とても思い罪を犯したということですね。

0 件のコメント:

コメントを投稿