Im trying to run a notification if a user has not opened an app in say 24 hours to encourage them to open it (Similar to duolingo style). Im using Java and I can set a periodic notification using workmanager but it runs while the app is open which is not what I want. I want the notification to run every 24 hours however if the user has opened the app this timer should reset, I've searched for this but can't find what I require exactly
I would recommend to use AlarmManager for your case. You can, for example, reschedule it in Application.onCreate() method to fire in 24 hours after user last launched an app. First you need to cancel previously scheduled alarm using cancel method, and then set a new alarm to fire in 24 hours using one of the set...() methods available in AlarmManager class.
Related
Basically I'm developing a social networking app and wanted to know, how I could give possible notifications to the users who have downloaded my app to open the app and use it. It could be on some time period too. But I want to know even when my app isn't running in the background, then how can I give notification to the user to open it and use it?
For reminding you can use alarm manger.
while exiting app sets alarm manager after 3 days.
If user opens app within 3 days then cancel alarm and while exiting app again set alarm manager
whenever the user opens the app store the devices current date in your machine using SharedPreferences and keep a service running in the background which will check the systems current date and the date you have stored in your SharedPreferences and according to your logic when you think it is too much time give the notification
Links
SharedPreferences &
service
My problem is: I need to start countdown timer in my app which will work independently my app is opened or closed ...or even if my smartphone is off.
I really wonder how does android standard clock app works. I mean how it counts time even when my phone is off? Could anybody help me with this? I will appreciate any answer!
Internal to an android device will be a clock which runs from the battery and potentially syncs with network time when it has signal.
You can use AlarmManager and PowerManager to get your code to run at specific times, even if the phone is turned off:
Sometimes, it may be necessary for your android app to complete a task
sometime in the future. In order to do this, you must schedule an
activity (can also be a service) to be run using Android’s
AlarmManager. This post will show: How to set up a receiver for the
scheduled event How to create an activity from this receiver Using the
AlarmManager and the created classes to successfully receive and
process a scheduled event
http://justcallmebrian.com/2010/04/27/using-alarmmanager-to-schedule-activities-on-android/
http://www.techrepublic.com/blog/software-engineer/use-androids-alarmmanager-to-schedule-an-event/
I develop an application which must manage the Alarm Clock in Android. I specifically need to do the following:
execute some code in my application when the user sets an alarm (also find out the time of the alarm at the moment of execution);
cancel an alarm when the user pushes a specific button in my application;
execute some code in my application when an alarm goes off.
I must mention that I am not interested in the CPU alarms, but the Alarm Clock application, which people use to wake up.
You can set an alarm using the intent described here.
However, you can not intercept the AlarmClock UI or ringing alarms as you seek to.
You might want to look into scheduling your own reminders, probably using AlarmManager with RTC_WAKEUP.
I'm working on an application where I need to show notifications 5 times a day ...from a foreground service..the purpose of using the foreground services is to be able to display notification even if the
application is closed . so I want to start the service as applications starts and schedule its notification timing accordingly I have tried using the snippet provided on android developers forum but its not working for me ... any help and sample code is highly appreciated Thanks
If the notifications are to be fired at a fixed time, you may not need a foreground service. It is a bad idea to keep a service running just to show notifications. Schedule those five times using an AlarmManager. You can find tutorial for it in google.
You would need to schedule alarms one by one. Foe ex..when alarm manager wakes your app the first time , then schedule a second alarm and son on.. You may not be able to set 5 concurrent alarm schedules. Do it one by one..
I want my app to access database every hour and read next record from the table then update desctop widget and send notification. I know that there is AlarmManager which I can use to register my Intents but they are deleted when the phone is turned off or rebooted.
Is there any other android class/service that I would update my application continuously even when I reboot my phone?
Thanks,
take a look at the demo applications provided with android sdk
http://developer.android.com/samples/RepeatingAlarm/index.html
the look at AlarmService_Service for the implementation of the service once the alarm has been triggered
put all of the background tasks you want to do in your app in Services which perform tasks in the background. In the service you should be able to define a timer that causes whatever updates you want to occur every x hours.
In the onCreate() of the widget, start the service. onCreate() is called every time that the widget comes to life (such as when the phone starts if it is on the home screen) and will therefore guarantee that the Service is always running.
Hope this was helpful.
Just for the sake of completness, I am linking here the official docs, where the issue of the rebooting is adressed.
http://developer.android.com/training/scheduling/alarms.html#boot