Android notifications actions without opening the app

后端 未结 3 2037
迷失自我
迷失自我 2020-12-31 04:40

I want to implement a notification action in JB. But it shouldn\'t open the app. The behaviour is similar to the Gmail apps delete notification action. How can I do this?

3条回答
  •  渐次进展
    2020-12-31 05:31

    You can also add custom buttons or layouts with onClickEvents to your notification compat (e.g. events which do not open the app ;)):

    1. Create a custom RemoteViews Layout and add it to the builder builder.setContent(remoteView);

      In this layout you can define Buttons

    2. Set an onClickPendingIntent to your control remoteView.setOnClickPendingIntent(R.id.button, pendingIntent);
      The PendingIntent can hold a BroadcastReceiver to trigger an action without jumping INTO the app

    Happy coding

提交回复
热议问题