NotificationListenerService
新しい 4.3 API をテストするための簡単な実装があります。サービス自体は以前は機能していました。その後、特定のパッケージの通知が追加されたときにブロードキャストを送信する機能を追加しました。今、サービスを開始するとすぐに、DeadObjectException
. これはスタック トレースです。
E/NotificationService﹕ unable to notify listener (posted): android.service.notification.INotificationListener$Stub$Proxy@42c047a0
android.os.DeadObjectException
at android.os.BinderProxy.transact(Native Method)
at android.service.notification.INotificationListener$Stub$Proxy.onNotificationPosted(INotificationListener.java:102)
at com.android.server.NotificationManagerService$NotificationListenerInfo.notifyPostedIfUserMatch(NotificationManagerService.java:241)
at com.android.server.NotificationManagerService$2.run(NotificationManagerService.java:814)
at android.os.Handler.handleCallback(Handler.java:730)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:137)
at com.android.server.ServerThread.run(SystemServer.java:1000)
これが私がサービスを開始する方法です
@Override
public boolean onOptionsItemSelected(MenuItem item) {
switch (item.getItemId()) {
case R.id.action_start_service:
startService(new Intent(this, ConnectService.class));
return true;
default:
return super.onOptionsItemSelected(item);
}
}
と にログオンするため、サービスが開始されたことを確認できonCreate()
ますonDestroy()
。必要に応じて、通知の投稿がどのように処理されるかを次に示します。
@Override
public void onNotificationPosted(StatusBarNotification sbn) {
Log.i(TAG, sbn.getNotification().toString());
if (sbn != null && sbn.getPackageName().equalsIgnoreCase(PKG)) {
Intent intent = new Intent(ConnectService.NOTIFY);
intent.putExtra("notification", sbn.getNotification().toString());
bManager.sendBroadcast(intent);
}
}
最悪なのは、スタック トレースが役に立たないことです。何がうまくいかないのですか?