My application runs in the background and gets a notification when the volume on the device changes. The service then has to show a warning message based on the volume levels.
What kind of a service should this be.
Thank you.
For achieving this, you need to register a broadcastreceiver. Take a look at this question:
Android BroadCastReceiver for volume key up and down
Related
I am developing an app and this app needs to give a clear indication to the user when some event happens.
Only thing I could do until now is giving a notification in the notification area. But, I need to give a more visible notification, similar to the behavior when phone is ringing in an incoming call.
As I can understand, the reason why android is only allowing apps to give a notification is to prevent apps from disturbing the user. But, this app I am developing plays a vital role in the job of the user, so I don't think it is inappropriate to give a such strong notification.
I know it should be doable since apps like Viber can start an activity similar to a incoming phone call, even when the device is sleeping.
Does anyone know how to get this done?
Register a broadcast receiver, and add a custom action to it say CustomAction.Instead of showing notification, throw a broadcast and add CustomAction via intent filter.
Now in the onReceive method of broadcast listener, check
if(intent.getAction.equals("CustomAction"))Intent i = new Intent(context, YourActivity);
context.startActivity(i);
Sorry for not a formatted answer, I'm driving, will update it later for more clarification.
Update
Register broadcast receiver in a sticky service. So that service can be started automatically if killed and register broadcast register again.
Don't forget to unregister broadcast receiver in onDestroy() method of service and also in YourActivity when you purpose is resolved.
Just adding a sticky service (which does nothing) fixed the issue. Adding the service prevented the process getting killed when user exits the app and removes it from recent app list.
Because of the service, the app process is running even when a no UI is visible. In this state, if an activity is shown from the GCM service, it gets shown.
You can trigger a broascast as Vinay mentioned. If it still does not work, try using wake-locks. These wake-locks help in waking the device when it is in sleep mode. It will act like force wake and after calling wake-locks, you can perform your actions.
Hope it helped..
Thanks.
I'm currently using NotificationListenerService to cancel notifications, and it's working fine.
I want to know if I can supress their sound and vibration, like when the phone is in INTERRUPTION_FILTER_ALARMS filter, making the notification only be shown, but make no noise at all.
Thanks
Unfortunately from what I know, I believe the answer is "no".
NotificationListenerService is just a listener. Android posts the notification and then notifies the NotificationListenerService. It seems not possible to intercept notifications. At least not this way.
I didn't find any documentation about that. Is it possible to create a foreground service on android wear? Usually the foreground state is related with an ongoing notification but it's not possible on wear so I'm a bit confused. Is there anyone has a foreground service on wear?
As per documentation:
"The system enforces a timeout period. If you are displaying an activity and user's don't interact with it, the device sleeps. When it wakes back up, the Wear home screen is displayed instead of your activity. If you need to show something persistent, create a notification in the context stream instead."
So, i believe it's possible to have a persistent UI (may be not an ongoing foreground notification but a card or a stack instead).
Hope it helps.
So in my app I'm looking to have the students class schedules and the times which they need to be in class.
When the app is turned off I still want the notification to pop up that their class is about to start (possibly vibrate).
This sort of functionality is very akin to an incoming text message or notification of something like an email. I was wondering how to implement that into an app?
You need a Service which can run when the app is not opened. You should also think about a BroadcastReceiver that listens to BOOT_COMPLETED
You will need to use the AlarmManager to set an alarm when you require the notification, possibly with the RTC_WAKEUP flag so the device will wake from a sleep. From your alarm receiver you will need to take a wake lock (if you used RTC_WAKEUP) and start a service that will use the NotificationManager to display a message to the user (very similar to the incoming SMS message).
As #WarrenFaith pointed out you will need to create a BOOT_COMPLETED receiver to re-establish the alarm after the phone is rebooted as they are not persistent.
I'm writing an alarm-based application, and I'm looking for a way to wake up the user insistently. Ideally, I'd like the phone to vibrate, ring, and display a message. I tried a few different options, here's what I have for the moment:
Have the background service start an activity that vibrates & plays music.
problem: even with a WAKE_LOCK, it seems that the user still has to turn on the screen and unlock it to see my activity
Use the AlarmManager with RTC_WAKEUP and a broadcast receiver to start the aforementioned activity
same issue
Simply pop up a notification, which the user can click to see the activity
problem: stil the same issue, and also I can't get the notification to vibrate and ring, and repeat often until dismissed
What I would really like is to have a behaviour similar to the basic Android morning alarm, or similar to receiving a phone call: regardless of whether your phone is awake or sleeping, it rings, vibrates and displays information such as a message, a photo...
Any tips on the direction to use would be greatly appreciated! I'm sure I've seen alarm apps or "fake phone call" apps do something similar, but I'm out of ideas.
Cheers
ps: in the context of this application, I think it would be reasonable to wake up the user this way. A discreet notification would not be appropriate - unless you can wake up to a single vibration :)
Have you looked at the ACQUIRE_CAUSES_WAKEUP flag? It looks like it should do what you want. See here for more information: http://developer.android.com/reference/android/os/PowerManager.html