2

I have a pause button in my notification, on click of which should go to the broadcast receiver. The following is my code:

NotificationCompat.Builder builder = new NotificationCompat.Builder(WalkTrackingActivity.this);
remoteViews = new RemoteViews(getPackageName(), R.layout.content_user_manual);
remoteViews.setChronometer(R.id.chronometer, SystemClock.elapsedRealtime(), null, false);

Intent intent = new Intent(WalkTrackingActivity.this, WalkTrackingActivity.class);
intent.setFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_CLEAR_TOP);
PendingIntent pendingIntent = PendingIntent.getActivity(WalkTrackingActivity.this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);

Intent fillInIntent = new Intent(this, pauseButtonListener.class);
fillInIntent.setPackage(getPackageName());
fillInIntent.setAction("PAUSE");
PendingIntent templateIntent = PendingIntent.getBroadcast(this, 0, fillInIntent, PendingIntent.FLAG_UPDATE_CURRENT);
remoteViews.setPendingIntentTemplate(R.layout.content_user_manual, templateIntent);
RemoteViews btnView=new RemoteViews (getPackageName(),R.id.imageButton5);
btnView.setOnClickFillInIntent(R.id.imageButton5, fillInIntent);



notification = builder
        .setSmallIcon(getNotificationIcon())
        .setContentIntent(pendingIntent)
        .setAutoCancel(true)
        .setOnlyAlertOnce(true)
        .setContent(remoteViews)
        .build();
notification.flags = Notification.FLAG_ONGOING_EVENT;
notificationManager = (NotificationManager)
        WalkTrackingActivity.this.getSystemService(Context.NOTIFICATION_SERVICE);


notificationManager.notify(0, notification);

I have registered my listner in manifest. Still it is not working. Please help!

Ramya Ramesh
  • 299
  • 3
  • 18
  • When you are using custom notification, then why are you using NotificationCompat.Builder? – Dhruv Apr 21 '16 at 12:51
  • Check first answer of this question: http://stackoverflow.com/questions/18367631/change-notification-layout – Dhruv Apr 21 '16 at 12:56
  • Why can't we use NotificationCompat.Builder along with custom notification? refer http://developer.android.com/guide/topics/ui/notifiers/notifications.html#CustomNotification – Ramya Ramesh Apr 21 '16 at 13:02
  • Have you check that link which is mentioned in my 2nd comment? – Dhruv Apr 21 '16 at 13:13
  • Yes I checked the link. However it is not possible to set small icon without using Builder..... notification.icon is deprecated. So how do I achieve this without using builder? – Ramya Ramesh Apr 22 '16 at 05:41
  • @Dhruv How else do you build a RemoteViews notification without **NotificationCompat.Builder**?? – IgorGanapolsky May 05 '16 at 15:24
  • @IgorGanapolsky http://stackoverflow.com/questions/18367631/change-notification-layout – Dhruv May 06 '16 at 07:31
  • @Dhruv You do realize they talk about using RemoteViews, right? – IgorGanapolsky May 06 '16 at 12:47

0 Answers0