Is there any way I can register one of my own activities, so it gets invoked whenever the notification drawer is opened? I know full well how to get my activity started when the user taps on my notification, but that's not what I want. I want my activity to run earlier -- at the moment the user pulls down the notification drawer and merely reveals my notification.
As you might imagine, I want my activity to update the notification's text (i.e. call NotificationBuilder.setContentText()).
It must be possible. For example, the 3G Watchdog app does this sort of thing (it has the notification show how much bandwidth you've used this month). I imagine this can be done if I write an app that can never die -- a daemon of sorts -- but I understand that's considered bad form in Android apps.
Related
I have project need to add notifications with Beacons。I have some questions wanna to make sure.
does os can receive beacon notification without APP running?
Can we show different showing content depend on different beacon notification?
can we open terminated app by beacon notification?
can the app do different behavior depend by the beacon notification content after start up?
Thanks。
1- How beacon works
The Android Beacon Library can launch your app into the background to
start looking for beacons after the phone boots. This will happen
transparently with no visible user interface, while the rest of your
app remains idle.
Once the desired beacon is detected, a callback method fires where you
can push a custom notification message. You can further configure the
notification so it launches a specific part of your app when pressed.
2- different notification
Yes ! each beacon has its id and you can handle showing different notification depending on the id and also different content
3- lunching app
Yes ! you can add your logic in the services that handle beacon notification method to start the preferred activity.
WARNING: launching a UI without any user interaction is a very very bad practice for most of the applications!
[...] Interrupting what the user is currently doing is considered bad
design form, especially from something that is supposed to be
operating in the background. Therefore, you should consider using a
Notification [...] to launch the desired Activity when the user
decides it is time to investigate. [...]
4- App behavior
Yes ! all you have to do is setting your pendingIntent accordingly to the notification
I want my app to silently start in the backgorund, without showing any activity on the screen.
It has a service which needs to perform 2 upload tasks.
I'm learning about service, but all boot-up launch of apps talks about showing the activity.
I need no activity to be shown.
Is that permitted after Oreo?
You didn't say what should trigger your app from background. I presume some kind of an Intent. As far as I know there is no way to start service in the background since android O without showing anything to the user. You should start your service using startForegroundService(), then show notification, perform your 2 uploads and turn off the app (hidding notification too). If those uploads aren't huge, it will be pretty quick, and in most cases user won't even see the notification.
I have a Worklight app that receives push notifications from the server. A notification means there are new messages for the current user from other users. A user would read them by visiting a messages page within the app and then proceeding to a particular conversation page.
I would like to differentiate in the code between user intentions. The app would:
If the user started the app normally (not by tapping a new notification), present the user with the regular app home screen.
If the user started/resumed the app by tapping a notification, present the user with the messages page.
If received while the app is on foreground, only update the on-screen message count (regardless of which page is active).
The question is: is there a reliable means to differentiate between the above conditions?
In another thread, I saw a suggestion to remember the timestamp of a resume event and an onReadyToSubscribe event and assume we were asleep/inactive if notification arrives e.g. just a second after this. This would enable me to differentiate between 2 and 3.
However, 1 is not covered by this. I.e. if there have been new messages, but the user started the app normally, the app would have no means of knowing this and would think it was started by tapping a notification. This way, the user intended to see app home screen, but we transfer him to the messages page.
Is there a reliable way around this for both iOS and Android?
Worklight vesion 6.2.0.00-20140922-2259.
In a pure Native application, you can know "where from the user opened the app", meaning whether it was by tapping on a received notification or by tapping the application icon.
In a Worklight-based Hybrid application, and if using only the JavaScript API, this is not feasible because all paths arrive to the same destination which is the pushNotificationReceived function. So whether you tapped a notification or the app icon or brought the app to the foreground, the aforementioned function will be invoked.
The solution may be to base your implementation on the following Knowledge Center documentation topic: Using native and JavaScript push APIs in the same app.
This way, using a combination of native code and JS code, you could handle the scenario where a notification was received but the user decided to tap the application icon rather than the notification.
An end-to-end example would to somewhat involved to implement, but if you'll follow the code examples in the documentation topic, you should get there...
I created a service to handle my AsyncTasks like uploading a file on a server or downloading one. When I swipe away my app from the recent activity menu, my service is killed. Is it normal behaviour ? If so, one solution would be to set it as a foreground service with startForeground(int, Notification) but I must display a notification and I don't want it as I'm already displaying one for each AsyncTask running.
How does the "play store" app download applications and keep the downloads alive even if I swipe away the "play store" from the recent activity menu ?
Is it normal behaviour ?
Yes. Android, at the user's request, terminated your background process.
If so, one solution would be to set it as a foreground service with startForeground(int, Notification) but I must display a notification and I don't want it as I'm already displaying one for each AsyncTask running.
Please do not show a separate Notification "for each AsyncTask running". At most, show one Notification. Few, if any, apps are important enough to warrant separate Notifications.
I have an alarm application where users can set multiple alarms. When an alarm goes off the app simply displays a Notification which when clicked will launch the main activity screen and remove the Notification.
Each alarm gets its own Notification which is where my question comes in; if there are multiple Noitifications showing, when the user clicks one I would like to clear all of my app's Notifications. To do this I need to track the IDs of the Notifications currently showing. What is the recommended way of doing this?
I suppose these will need to be persisted as my app's process could be killed as soon as a Notification has been created and displayed. Is my thinking correct?
To do this I need to track the IDs of the Notifications currently showing.
Or just call cancelAll() on NotificationManager, to cancel all your outstanding notifications.
What is the recommended way of doing this?
To be safe, you should use some persistent data store (e.g., file), as your process might go poof between alarms.
I suppose these will need to be persisted as my app's process could be killed as soon as a Notification has been created and displayed. Is my thinking correct?
It could certainly be killed before the next alarm, as discussed in your other recent question.