0

I am using the notification builder to notify the notification on the device. And all of this is working fine. I have implemented the pending intent. Whcih takes the user to the activity when ever user click the notificcation. Also when the user click on the notification the notification disappears as I wanted by setting the auto cancelable property to true.

Let me show you the way I am starting and notifying the notification

 mNotifyManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
mBuilder = new NotificationCompat.Builder(DownloadService.this)
                            .setSmallIcon(R.drawable.download)
                            .setContentTitle("MyApps")
                            .setContentText("Downloading new tracks");
            mBuilder.setAutoCancel(true);


            Intent targetIntent = new Intent(DownloadService.this,TrackClass.class);
            PendingIntent contentIntent = PendingIntent.getActivity(DownloadService.this, 0, targetIntent, PendingIntent.FLAG_UPDATE_CURRENT);

            mBuilder.setContentIntent(contentIntent);

            mNotifyManager.notify(1, mBuilder.build());

So this all is working fine Also I am showing the progress and updating the progress in the notification .

What I want: this is why I posted the Question ,

"I want to add the button along with the notification, so that when user click on the button it should close the service. I have implemented the click action on the notification But I have no Idea How to add the button in it"

Please tell me How Can I achieve this?

Note: Please keep in mind I am making and updating the notification in the service.

I think Now I am quite clear about what I want and what is my question all about. So please tell me how can I add the button in this notification ?

Edited 1:

I want that If I implement the custom xml for the notification , then the other attributes like showing my app name on notification and a little ticker message on notification , would they still be able to show by the side of notification , or I have to show them explicitly ?

Coas Mckey
  • 701
  • 1
  • 13
  • 39

1 Answers1

0

you have to create your own custom view all needed info here http://developer.android.com/guide/topics/ui/notifiers/notifications.html#Updating

public void createNotification(View view) {
// Prepare intent which is triggered if the
// notification is selected
Intent intent = new Intent(this, NotificationReceiverActivity.class);
PendingIntent pIntent = PendingIntent.getActivity(this, (int) System.currentTimeMillis(), intent, 0);

// Build notification
// Actions are just fake
Notification noti = new Notification.Builder(this)
    .setContentTitle("New mail from " + "test@gmail.com")
    .setContentText("Subject").setSmallIcon(R.drawable.icon)
    .setContentIntent(pIntent)
    .addAction(R.drawable.icon, "Call", pIntent)
    .addAction(R.drawable.icon, "More", pIntent)
    .addAction(R.drawable.icon, "And more", pIntent).build();
NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE);
// hide the notification after its selected
noti.flags |= Notification.FLAG_AUTO_CANCEL;

notificationManager.notify(0, noti);

}

AbuQauod
  • 919
  • 14
  • 30