I want to create a custom notification with a progress bar and a delete button.
Screenshot:

I was able to create a custom notification with a progress bar, but I was not able to create a delete event. I want to cancel the notification and stop the download as soon as the user presses "x" (as in google music, so I do not want to start the operation to clear the notification).
Here is my working code:
notificationManager = (NotificationManager) context.getSystemService(context.NOTIFICATION_SERVICE);
int icon = R.drawable.ic_launcher;
CharSequence tickerText = "Hello";
long when = System.currentTimeMillis();
notification = new Notification(icon, tickerText, when);
CharSequence contentTitle = "My notification";
CharSequence contentText = "Hello World!";
Intent notificationIntent = new Intent(context, UploadEventsReceiver.class);
PendingIntent contentIntent = PendingIntent.getActivity(context, 0, notificationIntent, 0);
notification.setLatestEventInfo(context, contentTitle, contentText, contentIntent);
notification.contentView = new RemoteViews(context.getPackageName(), R.layout.upload_progress);
notification.contentView.setOnClickPendingIntent(R.id.text, contentIntent);
notificationManager.notify(this.notificationId, notification);
In line
Intent notificationIntent = new Intent(context, UploadEventsReceiver.class);
I tried to use the BroadCast receiver without "broadcasting," but I don’t know if it did it right, and I couldn’t get it working. What should I use and how to use it?
source
share