来自通知的行动什么都不做

时间:2017-12-15 16:36:21

标签: android service notifications android-pendingintent remote-input

这是我的代码:

  Intent notificationIntent = new Intent(this, PSTimelineFragmentsActivity.class);
    PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0);
    NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(PSLocationService.this);
    mBuilder.setPriority(Notification.PRIORITY_MAX);
    mBuilder.setContentTitle(getText(R.string.passenger_name_long));
    mBuilder.setContentText(getText(R.string.service_subtitle));
    mBuilder.setSmallIcon(R.drawable.notification_icon);
    mBuilder.setContentIntent(pendingIntent);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT_WATCH) {
        Intent action1Intent = new Intent(PSLocationService.this, NotificationActionService.class)
                .setAction("autopilot").putExtra("autopilot", "autopilot");
        PendingIntent action1PendingIntent = PendingIntent.getService(PSLocationService.this, 0,
                action1Intent, PendingIntent.FLAG_ONE_SHOT);

        Intent action2Intent = new Intent(PSLocationService.this, NotificationActionService.class)
                .setAction("settings").putExtra("settings", "settings");
        PendingIntent action2PendingIntent = PendingIntent.getService(PSLocationService.this, 1,
                action2Intent, PendingIntent.FLAG_ONE_SHOT);

        RemoteInput remoteInput = new RemoteInput.Builder("autopilot")
                .setLabel("Stop")
                .build();
        NotificationCompat.Action action1 =
                new NotificationCompat.Action.Builder(R.drawable.icn_terms_settings,
                        "Stop", action1PendingIntent)
                        .addRemoteInput(remoteInput)
                        .build();

        RemoteInput remoteInput2 = new RemoteInput.Builder("settings")
                .setLabel("Settings")
                .build();
        NotificationCompat.Action action2 =
                new NotificationCompat.Action.Builder(R.drawable.icn_terms_settings,
                        "Settings", action2PendingIntent)
                        .addRemoteInput(remoteInput2)
                        .build();
        mBuilder.addAction(action1);
        mBuilder.addAction(action2);
    }
    Notification notification = mBuilder.build();
    startForeground(1338, notification);

但每当我按下通知时,我都会收到此错误:

12-15 17:35:06.553: D/StatusBar(933): Clicked on button 0 for 0|nl.hgrams.passenger|1338|null|12567
12-15 17:35:06.555: E/RemoteViews(933): Cannot send pending intent: 
12-15 17:35:06.555: E/RemoteViews(933): android.content.IntentSender$SendIntentException
12-15 17:35:06.555: E/RemoteViews(933):     at android.app.ContextImpl.startIntentSender(ContextImpl.java:753)
12-15 17:35:06.555: E/RemoteViews(933):     at android.content.ContextWrapper.startIntentSender(ContextWrapper.java:390)
12-15 17:35:06.555: E/RemoteViews(933):     at android.content.ContextWrapper.startIntentSender(ContextWrapper.java:390)
12-15 17:35:06.555: E/RemoteViews(933):     at android.widget.RemoteViews$OnClickHandler.onClickHandler(RemoteViews.java:217)
12-15 17:35:06.555: E/RemoteViews(933):     at com.android.systemui.statusbar.BaseStatusBar$3.onClickHandler(BaseStatusBar.java:323)
12-15 17:35:06.555: E/RemoteViews(933):     at android.widget.RemoteViews$SetOnClickPendingIntent$1.onClick(RemoteViews.java:720)
12-15 17:35:06.555: E/RemoteViews(933):     at android.view.View.performClick(View.java:5204)
12-15 17:35:06.555: E/RemoteViews(933):     at android.view.View$PerformClick.run(View.java:21153)
12-15 17:35:06.555: E/RemoteViews(933):     at android.os.Handler.handleCallback(Handler.java:739)
12-15 17:35:06.555: E/RemoteViews(933):     at android.os.Handler.dispatchMessage(Handler.java:95)
12-15 17:35:06.555: E/RemoteViews(933):     at android.os.Looper.loop(Looper.java:148)
12-15 17:35:06.555: E/RemoteViews(933):     at android.app.ActivityThread.main(ActivityThread.java:5417)
12-15 17:35:06.555: E/RemoteViews(933):     at java.lang.reflect.Method.invoke(Native Method)
12-15 17:35:06.555: E/RemoteViews(933):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:726)
12-15 17:35:06.555: E/RemoteViews(933):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)

1 个答案:

答案 0 :(得分:0)

RoutesPageViewController更改为导致其正常工作的FLAG_ONE_SHOT