Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android: Adding a button on a status bar notification

Tags:

android

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.

like image 779
user192629 Avatar asked Sep 11 '10 23:09

user192629


People also ask

How do I add buttons to my notifications?

Step 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project. Step 2 − Add the following code to res/layout/activity_main. xml. Step 3 − Add the following code to src/MainActivity.

How can I customize my Android status bar?

To customize it, first pull down the slider bar from the top of the screen. Next, tap on the three vertical dots in the top right corner. Now click on Status bar. You're in.


3 Answers

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)

like image 178
FixerMark Avatar answered Oct 20 '22 19:10

FixerMark


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

like image 25
user998953 Avatar answered Oct 20 '22 19:10

user998953


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.

like image 45
Falcon Avatar answered Oct 20 '22 19:10

Falcon