相关疑难解决方法(0)

NotificationListenerService实现

我正在尝试实现在Android 4.3中添加的NotificationListnerService,但我无法获取通知详细信息.

我的代码如下

public class MainActivity extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(this);
        mBuilder.setSmallIcon(R.drawable.ic_launcher);
        mBuilder.setContentTitle("notification test");
        mBuilder.setContentText("Notification text");
        mBuilder.setAutoCancel(true);
        Intent resultIntent = new Intent(this, ResultActivity.class);
        TaskStackBuilder stackBuilder = TaskStackBuilder.create(this);
        // Adds the back stack for the Intent (but not the Intent itself)
        stackBuilder.addParentStack(ResultActivity.class);
        // Adds the Intent that starts the Activity to the top of the stack
        stackBuilder.addNextIntent(resultIntent);
        PendingIntent resultPendingIntent =
                stackBuilder.getPendingIntent(
                    0,
                    PendingIntent.FLAG_UPDATE_CURRENT
                );
        mBuilder.setContentIntent(resultPendingIntent);
        NotificationManager manager = (NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE);
        manager.notify(1, …
Run Code Online (Sandbox Code Playgroud)

android android-service android-notifications

17
推荐指数
5
解决办法
4万
查看次数

使用NotificationListenerService时,getActiveNotifications始终为null

我遵循了这个kpBird示例代码和本开发人员指南

我可以 :

  • 调用此服务的意图.

  • 可以从通知中捕获广播.

所以我得到了错误getActiveNotifications always null.

我不知道为什么,

知道的人,请帮助我,

谢谢,

p/s:这是我得到的源代码和错误.

错误:

04-28 08:46:11.625: E/AndroidRuntime(7651): FATAL EXCEPTION: main
04-28 08:46:11.625: E/AndroidRuntime(7651): java.lang.RuntimeException: Error receiving broadcast Intent { act=app.trekband.NotificationListener flg=0x10 (has extras) } in utils.NotificationListener$NLServiceReceiver@42680780
04-28 08:46:11.625: E/AndroidRuntime(7651):     at android.app.LoadedApk$ReceiverDispatcher$Args.run(LoadedApk.java:778)
04-28 08:46:11.625: E/AndroidRuntime(7651):     at android.os.Handler.handleCallback(Handler.java:730)
04-28 08:46:11.625: E/AndroidRuntime(7651):     at android.os.Handler.dispatchMessage(Handler.java:92)
04-28 08:46:11.625: E/AndroidRuntime(7651):     at android.os.Looper.loop(Looper.java:176)
04-28 08:46:11.625: E/AndroidRuntime(7651):     at android.app.ActivityThread.main(ActivityThread.java:5419)
04-28 08:46:11.625: E/AndroidRuntime(7651):     at java.lang.reflect.Method.invokeNative(Native Method)
04-28 08:46:11.625: E/AndroidRuntime(7651):     at java.lang.reflect.Method.invoke(Method.java:525)
04-28 08:46:11.625: E/AndroidRuntime(7651):     at …
Run Code Online (Sandbox Code Playgroud)

service notifications android broadcastreceiver android-notifications

2
推荐指数
1
解决办法
8239
查看次数