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.
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.
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.
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)
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
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With