Android - jelly bean notification dismiss button - android

The google play music app has a little 'X' in the top right corner, instead of displaying the time and a miniature notification icon in that location. Tapping the button kills the player and closes the notification. Great!
I'd like to do the same with my app - Is this only possible by inflating remote views and associating a custom button with an intent to destroy the service, or is there some notification builder methods that I'm overlooking which do that job?

There are no notification builder methods which achieve this. The only solution is to create a custom button with a pending intent to perform the action required.

Related

What's the difference between setContentIntent and setFullScreenIntent in Android?

It seems like both involve showing a notification and then the user can touch the notification to launch your activity.
https://developer.android.com/training/notify-user/build-notification
Every notification should respond to a tap, usually to open an
activity in your app that corresponds to the notification. To do so,
you must specify a content intent defined with a PendingIntent object
and pass it to setContentIntent().
https://developer.android.com/training/notify-user/time-sensitive
Use a full-screen intent only for the highest-priority alerts
where you have an associated activity that you would like to launch after the user
interacts with the notification.
So it seems like in both situations a notification shows that the user must interact with and then your activity is launched.

is there any listener after performing clear notification in android?

Basicly I want to do something after the user clear my notification from the top bar, How do I do that in andorid programmatically?
Basic example or complete code would be nice thanks.
When you create a Notification,setDeleteIntent ,Here is the api:
setDeleteIntent(PendingIntent intent)
Supply a PendingIntent to send when the notification is cleared explicitly by the user.

IconLevel and startForeground

I would like to animate the icon of the app without having to cancel the notification and create a new one (because in this way the icon doesn't stay in the same position of the notification bar but could move to first place if there are other notification running).
I'm able to get this with normal notification, but I would like to get the same behaviour when I use startForeground in my service. This method launches a new notification which can't be removed unless you remove service from foreground using stopForeground.
Is this possible to do? How?
Use the same notification ID for the startForeground method and the Notification object.

Status bar Notification in android

I want to set a onClickListner for a status bar Notification. How it is possible ? Please help. Now i can load a Activity by using the pending intent. I like to set a onClickListner for the notificatioin.
Regards
Parvathi
It is not possible to set an OnClickListener for a notification. Because of the way notifications are handled/displayed there is no way to guarantee that the process that created the notification will be running at the time the notification is clicked. This means that any code you wrote to provide click handling may not be running.
If you need click listener style behavior you will have to do it using the PendingIntent: set it to start a Service that runs the logic or to use an Intent that is received by a BroadcastReceiver. This will let you perform activity without requiring a UI.

How can I keep my ongoing audio task ongoing?

I'm having a specific problem that I'd love some insight on. Here is my code
Intent i = new Intent();
i.setDataAndType(media, mediaType);
startActivity(i);
This starts an audio activity for me and it even puts a notification item in the notification bar saying that it is an ongoing task. However, if I hit the Home button or Back button the ongoing task is immediately killed for me. I was confused by this behavior.
I found a way to keep the task going by the following: when the audio activity starts I drag down the notification bar and click the notification item ( which really just shows me the same activity again ) and when I do this it behaves accordingly. When I click the Home button it continues. When I hit the back button, it continues. For some reason when I click the notification item the "correct" Intent is fired.
What I'd like is for this behavior to start when I first launch the audio, because no one that uses my app is going to pull down the notification bar and click the notification item to get this to work properly.
Use a Service. Specifically, you will want to call startForegroundService() in the service's creation/start callback.

Categories

Resources