17

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?

Thanks in advance, Shashika

Shashika
  • 1,151
  • 1
  • 9
  • 21

3 Answers3

24

After some research I managed to achieve this using a broadcast receiver. I posted the example code here. http://shashikawlp.wordpress.com/2013/05/08/android-jelly-bean-notifications-with-actions/

Shashika
  • 1,151
  • 1
  • 9
  • 21
2

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

0xPixelfrost
  • 10,244
  • 5
  • 39
  • 58
  • setContent replaces platform template, OP only asks about notification action not replacing the whole template. – Error Jan 04 '17 at 11:01
0

From what I understand of what your asking, you need to run a AlarmManager that launches background services at specified times to create notifications, and then you need to specify the intent for the notification to do what you want it to do.

If you are getting Push notifications, then forget the AlarmManager and just launch the action you want to do from the intent in the notification.

For more specific answer we need a more specific question.

WIllJBD
  • 6,144
  • 3
  • 34
  • 44
  • I'm uploading some files to a server by running a foreground service. And I need to add a cancel upload button to the notification. Like this http://developer.android.com/images/jb-notif-ex1.png But I don't want the app to open. – Shashika May 06 '13 at 06:10