Android - Buttons supported in notification expanded view? - android

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!

Related

Wearable Notification that is updated frequently causes flicker

On a wearable my app displays a rest timer as shown in the picture. It simply counts down and is updated each second.
My problem is that since it is updated each second, it creates a flickering effect.
The icon is hidden for just long enough for you to be able to notice it.
The actions related to the card (accessible through swiping) also flicker similarly, and at times display the totally wrong information such as another items icon and text. The actions are same for the whole duration of the rest timer.
Ive tried updating it each 5 seconds or so but it unfortunately ruins the whole thing and makes it very unintuitive. Its my best option at the moment though.
Is it possible to update the notification each second without causing the flicker?
If you want to show a notification with a timer, either counting up or down, that's a built-in feature for that. Here's some code I wrote that puts it all together for Android Wear:
https://github.com/danwallach/XStopwatch/blob/master/wear/src/main/java/org/dwallach/xstopwatch/NotificationHelper.java
Notably, you'll want your notification builder to do something like this:
builder.addAction(android.R.drawable.ic_media_pause, "", clickPendingIntent)
.setWhen(eventTime)
.setUsesChronometer(true)
.setShowWhen(true);

How to add splash art to an android notification

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.

How to add a button into notification?

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

Android: Adding a button on a status bar notification

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.

Should one use an Activity or a Service when using a button in a Widget?

I'm been trying to figure this out for a while now, and have just become more and more confused.
I have made a Android Widget which displays two articles (title + image). In addition to this, I have buttons for flipping backward and forward through the articles. What I don't understand is how I can change the Widgets RemoteViews when the buttons are pressed. Which should be one of the most basic operations in a widget, however, I can't seem to figure it out.
So...
Can I do this with just a OnClickListener in the AppWidgetProvider?
Or do I have to create an Activity without a window (visibility = false)?
Please excuse my stupidity. This is probably very basic.
I don't think this is basic at all - it's something I thought about for a while in relation to the Headset Blocker app I wrote, which is just a widget that you toggle on/off.
I ended up looking through Google's source code for what they did. The answer is to use the AppWidget's receiver nature to receive updates via setOnClickPendingIntent(). Then in onReceive(), you react differently to your own clicks than someone trying to create a widget. You can see a sample of what I did in the Headset Blocker source.
Ultimately, an Activity or a Service is too heavy weight for what you want. Using the same BroadcastReceiver as the app widget itself is much better.

Categories

Resources