Android notifications actions without opening the app - android

I want to implement a notification action in JB. But it shouldn't open the app. The behaviour is similar to the Gmail apps delete notification action. How can I do this?
Thanks in advance,
Shashika

After some research I managed to achieve this using a broadcast receiver. I posted the example code here. http://shashikawlp.wordpress.com/2013/05/08/android-jelly-bean-notifications-with-actions/

You can also add custom buttons or layouts with onClickEvents to your notification compat (e.g. events which do not open the app ;)):
Create a custom RemoteViews Layout and add it to the builder builder.setContent(remoteView);
In this layout you can define Buttons
Set an onClickPendingIntent to your control remoteView.setOnClickPendingIntent(R.id.button, pendingIntent);
The PendingIntent can hold a BroadcastReceiver to trigger an action without jumping INTO the app
Happy coding

From what I understand of what your asking, you need to run a AlarmManager that launches background services at specified times to create notifications, and then you need to specify the intent for the notification to do what you want it to do.
If you are getting Push notifications, then forget the AlarmManager and just launch the action you want to do from the intent in the notification.
For more specific answer we need a more specific question.

Related

Notification sent via PendingIntent does not show up

In one of Activity-derived class methods I'm trying to send a Notification, clicking on which will bring the Activity to foreground if my app is in background (not visible) right now. There are reasons why I don't use Service, but use Activity (that will hold PARTIAL_WAKE_LOCK) for that.
I remember Notification worked for me when I used it like this, but I sent it from Service. Now when I send it from Activity method and it doesn't show up, though I hear its notification sound.
So are there any reasons that prevent Notification show up sent from Activity method and how can it be solved?
Thank you.
I was not exactly precise copying Notification code sample. I removed setSmallIcon() call from code as I was too lazy to add icons. As a result system was really dropping my Intent, saying that no icon is provided for it and it'll be a crash in future releases.

Detect when Notification is clicked to send analytic's event

We have an app with GCM notifications working fine, we set a PendingIntent so the activity that we want is open when the notification is clicked. However, we need to send an event to Google Analytics each time that one notification (and there are different types of notifications) is clicked. How could we achieve this? I don't want to parse the intent in the activity, as I think that this would not be a good solution (we are using TaskStackBuilder so not always the same activity is open for the same notification), is there a receiver we can use to detect when the notification is clicked/open?
Thanks in advance
put some flag variable on your notification intent.
intent.putExtra("notification","clicked");
Now check it in your Activity, whether Bundle is having "notification" key or not
if(getIntent().hasExtra("notification"))
//write your code for analytics
Try using NotificationListenerService. It allows an application to receive information about notifications. You need to declare the service in your manifest file with the BIND_NOTIFICATION_LISTENER_SERVICE permission and include an intent filter with the SERVICE_INTERFACE action to extend this class. See this example.
I also found this stackoverflow question on how to implement NotificationListenerService using TaskStackBuilder. This might help.

Android: Is there a method for after-notification-is-sent?

Trying to implement a snooze functionality on notification. (Correct me if I'm wrong) So I think one of the ways is to modify the alarm manager when the notification is triggered. So anyone knows if there is a method that's called when the notification is called? Thanks in advance.
So anyone knows if there is a method that's called when the notification is called?
I have no idea what you consider "the notification is called" to be.
You provide a PendingIntent to the Notification that will be invoked when the user taps on the Notification in the notification drawer. Usually, that PendingIntent will point to your code: activity, service, or BroadcastReceiver.
For Android 4.1 and higher, you can also have a "big" Notification style that has its own buttons, and you can tie a PendingIntent to each button.
Hence, on Android 4.1 and higher, I would expect "snooze" to be one of these action buttons, and you could use a broadcast PendingIntent to get control and make your changes to your alarm schedule. On Android 4.0 and earlier, "snooze" would be part of the activity that would come up when the user taps on the Notification, and you can adjust your alarm schedule at that point.

How to achieve this in Android?

I am looking at Avast, Lookout for example and I am trying to understand the concept of the implementation. So it is more like asking for direction for me.
Persistent App icon in Notification bar.
Am I correct to say there are function NotificationManager is able to do it?
Scan virus during app installation, I am not interested in virus scanning but the triggering mechanism.
Some kind of Android service bind to the main app?
Main app that can be bring up in the Notification menu.
A main app that remain trigger action to the bind services?
So what do I need to read to understand? NoticationManager, Services and ??
In short, I want to load a icon in the notification bar that can bring up my app. There is a background service that perform specific task for a set interval.
Yep, NotificationManager and Notification can help you with that.
You just need to create the notification with flag FLAG_ONGOING_EVENT (to make it persistent). Even better if your service IS REALLY performing some long-running task, if so, you can start your service via Service.startForeground which needs some 'ongoing' notification for running (notification is required to notify the user that there is some work going now).
For triggering app install event, you can use BroadcastReceiver with filter by Intent.ACTION_PACKAGE_ADDED.

Auto Notification for Android

I'm new with Android programming. I'm just wondering whether its possible to set up auto notification. For example, every morning at 8am, the app will send a notification to user about something. Is this possible? Which area/class of Android programming should I look at? Thanks!
You should have a look at the Alarm Manager. You will need to use either of the 'set' methods, and give it a PendingIntent that will perform a broadcast or start an intent service that wakes up just to show the notification. For the broadcast, you will need to have a receiver in your app, that makes a Notification and shows it.

Categories

Resources