I do it like this:
RemoteViews views = new RemoteViews(..);
views.setOnClickPendingIntent(R.id.button1,pd);
noti.contentviews = views;
and then notify the notification.
I can see the button in the notification,
but the button can't be clicked.
When i click the button,the whole notification clicked!
How can i resolve this question?
I found everywhere for this,but nothing useful found.
someone said, some phones don't support the notification button,
but samsung galaxy s, the musicplayer's notification has button click event.
You cannot put interactive widgets, like a Button, in a Notification and get user input from them. These are for output display only.
We can made custom notification and put buttons into that and also can perform different functionality on that onClick function, recently I was stuck in the same problem but this link
Handling buttons inside android notifications
save my life.
You can also see my code here
Adding button action in custom notification
and it actually works on my HTC Sensation XE havent tried on other devices yet. So cheer and good luck
Related
I came across this notification while doing some research and it has me wondering... how do you include this splash art in the notification list on Android?
I have not seen an Android app do this before. Checking Google's documentation (https://developer.android.com/preview/notifications.html), I don't see it mentioned.
Any thoughts or ideas on how this is accomplished?
http://postimg.org/image/mtan1vcfn/
You need a custom notification layout via RemoteViews. Have a look at the documentation.
You first create a RemoteViews with your custom layout. This is the normal XML file you are used to. Then call the Notification.Builder.setContent() and pass in your RemoteViews.
And, dont forget to set the small icon for your notification or else it just wont display.
the screenshot contains notifications from two different applications.
in the upper notification , there is a cancel button, How to add that button in notification.
Any help will be extremely thankful.
Use a Custom Notification Layout as outlined in the documentation.
You'd need to create a notification with a custom layout (view here) how to do that. You can attach a click listener with a pending intent to a button like so.
I have an AppWidget (part of my app). I want there to be no sound when the user clicks a button in the widget.
How do I do this?
CommonsWare answered it:
This is not a method on RemoteViews, and setSoundEffectsEnabled() is not a RemotableViewMethod, so the literal answer is incorrect. However, android:soundEffectsEnabled="false" in the layout file may work.
setting android:soundEffectsEnabled="false" in the xml layout file does indeed work!
As far as I know, you have to turn off notification sounds (pressing volume down, then selecting settings on it). The click sound is usually created by the OS (Samsung Android will have a click but google Nexus will not). The only other way I can think of is, if the widget is yours, create a custom button that overrides that particular functionality.
Add the following line of code to disable the click sound,
yourbutton.setSoundEffectsEnabled(false);
I am trying to get buttons to work in notification expanded view. The goal is to use the buttons to launch activities from the notification view. Is this even supported? Here is a very simple outline with irrelevant details omitted:
Create a RemoteView object using a layout with some ImageButtons.
Create pending intent for each button and set them using RemoteView.setOnClickPendingIntent(...)
Create a Notification object and set it's contentView as the RemoteView created in step 1.
Set Notification object's contentIntent.
Send the Notification.
This works beautifully on my Droid X. I can click on each button and launch it's associated activity successfully.
This works on my pal's Evo 4G as well, except that it launches the button's intent plus the notification's content intent. So two intents launched. But I can deal with that.
This also works on HTC Incredible.
Unfortunately, it doesn't work on most other phones: Vibrant, Hero, Vision, WildFire, MIleStone, Droid 1. These are the ones I know so far based on user feedback. On these phones, only the notification contentIntent is being launched. It appears the button's click events aren't being captured/detected.
I am at my wit's end trying to work around this. I am beginning to think it's impossible, but it works on some phones! Any suggestion/help is appreciated.
Thanks!
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.
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.