There is a notification ( notification ) with a custom View .
Question. How to catch events from the service seeming buttons in the notification? Found that this is done via setOnClickPendingIntent , there is the second parameter PendingIntent .
I do not know how to use.
|
1 answer
Create PendingIntent :
Intent intent = new Intent(context, YourService.class); PendingIntent pendingIntent = PendingIntent.getService(context, 123, intent, PendingIntent.FLAG_UPDATE_CURRENT); Add a notification action:
.addAction(R.drawable.ic_icon, "text", pendingIntent); Catch in service, process in onStartCommand :
public int onStartCommand(Intent intent, int flags, int startId) { //обработать интент return Service.START_STICKY; } |