Android: creating an insistent alarm (ex: morning alarm, incoming call) - android

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

Related

Is there any special step to make to make a repeating alarm ring on Android?

I am building a reminder app and need to implement repeating alarms. Following the Android documentation on the topic everything runs okay except that:
Phone does not wake up if locked.
Phone won't ring.
When setting a regular alarm, the phone would ring (but never wake up). I would like to solve these two issues for repeating alarms. I'm on API 29.
Thanks in advance!

Block Android Notification during night time

I am trying to find documentation or a cleaner way of not showing notification(programmatically) during nighttime (sleeping hours). I have a service that periodically checks if certain conditions are met and then I fire the notification. I would want to avoid this when the user is sleeping.
I don't really think you need to. If the user wants to block notifications, they'll put the device in Do Not Disturb mode which blocks all notification. I have one set to automatically turn on at night and off in the morning. Bonus- when the DND turns off, I get all the notifications I miss. This is a feature of the Android OS.
If you really wanted to do this- just check the time before you put up a notification. If its too late, don't fire it. Optionally, set an alarm for when you think its late enough, and decide if the user should see them now.
Do you mean to keep running the program at night without using notifications?
You only need to use WorkManager, JobScheduler or AlarmManager to achieve.

Turned off "Allow background activity" setting stops location updates in foreground service

I have a foreground service requesting location updates and doing stuff with them.
When the app is not on screen, it still works because the service has an ongoing notification.
But there is a battery setting, at least on my samsung device, called "Allow background activity".
I wasn't paying attention to it because it says 'background', and as far as I know, as long as I have a foreground service with ongoing notification, my app is regarded by android as in foreground, and never in background.
But I've noticed that, if that setting is turned off, my ongoing notification is still there, but the gps icon disappears and location updates stop coming.
Is this normal behavior or I'm doing something wrong? Shouldn't my app be regarded as in foreground instead?
In case it is normal behavior, I'm aware now that I can detect this status with isBackgroundRestricted(), and I can use that to notify the user that they need to change it.
The other question is, is there a way to programmatically open the exact settings page where the user should make this change?
Thank you!
I had a similar question here. Short answer is I don't think there is an intent to go to the exact screen, but you can get the user there using android.provider.Settings.ACTION_APPLICATION_SETTINGS.

Stopping an app from starting on boot

I have an app that starts when the phone starts. In the app I have an option for the user to stop showing a notification from the app. The notification is related to the boot_complete action (it starts a service). I'm wondering how would I stop the App from starting on boot up if the notification is turn off? I'm thinking on setting a shared preference to "No" if the notification is turned off and then check that on the boot complete broadcast. If the preference is set to "No", then nothing will start if it's set to "Yes" then it will start. Is that the best way of doing it or is there a better way to do it?
Yes this is the best way to do this, just implement it in your BroadcastReceiver. I have implemented this multiple times in my apps, it seems to work well.

Invoke a Service even when the Device is Switched Off

I am working on a Security application, where i need to play siren music on receiving certain text(say "siren").
So far, I've been able to receive the SMS intent and play the .mp3 siren music. But the problem encounters when the device is switched off.
Its been to my knowledge that there are some Intents(dont know what exactly to call them), those intents are fired even when the Device is switched off, just like the Scheduled Alarms (which executes even when the phone is switched off)
If anyone knows about those services or whatever they are, it would be helpfull if you share those ideas.
If you need device to be awaken when you do your tasks, then simply wake it up using PowerManager. Please note that once your onReceive() is completed device may fall back to sleep, so if you spawn some other processed in your BroadcastReceiver, you need to hold WakeLock.
You may take a look at this as well: https://github.com/commonsguy/cwac-wakeful
Maybe this might help.. Shouldn't be that hard to do but how can you get a text message if the phone is turned off?!
http://developer.android.com/reference/android/app/AlarmManager.html

Categories

Resources