I have notification with custom view that contains button. When user press the button in notification it should get some Toast message. However Toast never shows up because onReceive is never called. What I'm doing wrong?
int icon = R.drawable.play; long when = System.currentTimeMillis(); Notification notification = new Notification(icon, "Custom Notification", when); RemoteViews notificationView = new RemoteViews(this.getPackageName(),R.layout.notification); PendingIntent listenerIntent = PendingIntent.getService(this, 0, new Intent(this, AudioControlListener.class), 0); notificationView.setOnClickPendingIntent(R.id.background, listenerIntent); notification.contentView = notificationView; Intent notificationIntent = new Intent(this, MainActivity.class); PendingIntent contentIntent = PendingIntent.getActivity(this, 0, notificationIntent, 0); notification.contentIntent = contentIntent; startForeground(1, notification); my broadcast receiver class
public static class AudioControlListener extends BroadcastReceiver { @Override public void onReceive(Context context, Intent intent) { Toast.makeText(context, "Button pressed", Toast.LENGTH_SHORT).show(); } }
onReceivemethod.