18

I am trying to create a custom status bar notification in Android that has a button in addition to the text. The button can do a different thing than when you click the notification itself. Is this possible at all? I'd also be ok putting an image of a button there instead. I know how to put an image, but not sure how to handle OnClick for an image embedded in RemoteViews. Your help is sincerely appreciated.

Thanks a lot in advance.

user192629
  • 303
  • 2
  • 4
  • 8

3 Answers3

4

I don't think you can get a button on the status bar itself but you can certainly do it using a Custom Expanded View (see http://developer.android.com/guide/topics/ui/notifiers/notifications.html)

FixerMark
  • 739
  • 6
  • 15
  • Ah. Thanks. That was actually what I meant. I am still not sure how to do it. It seems I have to use RemoteViews which doesn't have a member fun for adding a button. How do I set an OnClick for the button? Sorry if this is too newbish – user192629 Sep 12 '10 at 20:32
  • 3
    There is setOnClickPendingIntent which should **in theory** allow you to trap a click on any object (including your button) but I don't seem to be able to get it to work in this application. Has anyone had any success with this function? – FixerMark Sep 13 '10 at 16:02
  • I have the same problem. I supply the button id as the viewID and the pendingIntent I wish to fire when the button is clicked, but nothing changes. When any point in the notification view is clicked (including the button), the main pendingIntent, notification.contentIntent, is fired. – Gallal Jun 03 '11 at 22:36
  • @Gallal, have you found a solution to this? Calling setOnClickPendintIntent with the button's id does not seem to work. – garbagecollector Jul 16 '12 at 21:20
  • @Gallal, you need not setImageViewResource and setTextViewText for your RemoteViews. When they are set, the contentIntent and the button's PendingIntent will both get called. – KITT Jun 17 '11 at 13:01
1

try use this way,the first is the view ID, the second is a Pending intent..

RemoteViews.setOnClickPendingIntent(R.id.push_notifi_content, Pdit);

I have try it,but seems it just support in android4.0

user998953
  • 654
  • 5
  • 16
  • 1
    It is also possible in Android 2.3.4 (at least on my SGS2), I am using the Mp3-Player "PowerAMP" and it has several Buttons in its notification. – Nippey Oct 11 '12 at 12:12
1

I am working on this end as well. It is straightforward from HoneyComb onwards: look at the music app (it has a status bar control when playing). And you can implement yours with your_notification_remote_view_instance.setOnClickPendingIntent(R.id.a_button_in_notification, pending_intent_to_be_handled_by_a_service); while backing it with a service to handle the intent properly of course. While buttons can be embedded in earlier versions, they don't get focus or click when pressing.

Falcon
  • 1,317
  • 1
  • 13
  • 30