How to avoid SystemAlarms creeping to my application getNextAlarmClock() of my application - android

I am building an application where I set Alarms for particular times.For this, I used AlarmClock of Android's to set Alarms.Here I try showing next AlarmClock time on his application to know the very next alarm.
Eg: I set 9:00AM, 6:00PM alarms using alarmManager.setAlarmClock(...) ,My Application shows next Alarm time using alarmManager.getNextAlarmClock() on homescreen saying 9:00AM.
Here is an issue I am facing where when I set some other alarms on my System provided Clocks App and set Alarm for 8:00 AM.This alarm time is getting reflected in my application next alarm time showing that the next time is set for 8:00 Am instead of 9:00 AM., which it is not supposed to.
private String getNextAlarmClock() {
AlarmManager alarmManager = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
AlarmManager.AlarmClockInfo alarmClockInfo = alarmManager.getNextAlarmClock();
Log.d(TAG, "time of next alarm in millis" + alarmClockInfo.getTriggerTime());
return alarmClockInfo.getTriggerTime() + "";
}
could anyone please help me in this regard.
This help is Appreciated, please.
Thanks in Advance!

If you call System Alarm manager, then this is common to all the applications in your mobile. And getNextAlarmClock() will give you the next alarm set in your mobile and not by your application. If you want alarm specific to your application, then you have to create this without using Alarm Manager.
If you are ok to get alarmed by system alarm manager and issue is only with display of next alarm time, then i would recommend to use system alarm manager to set time and save this information to DB/shared preference. To display next alarm time, you can fetch saved data from DB instead of taking from alarm manager.

Related

Registering an alarm in Android, where does it go?

I have an Android application which provides users in a particular city info on food and drink deals. I would like to create an alarm so that a user can click "Remind Me" and when a particular deal begins (such as 2pm) the app opens to that specific info.
Here is the code that creates my alarm:
AlarmManager alarmMgr;
PendingIntent alarmIntent;
alarmMgr = (AlarmManager)this.getSystemService(Context.ALARM_SERVICE);
Intent intent = new Intent(this, ViewListingActivity.class);
alarmIntent = PendingIntent.getBroadcast(this, 0, intent, 0);
Calendar calendar = Calendar.getInstance();
calendar.setTimeInMillis(System.currentTimeMillis());
calendar.set(Calendar.HOUR_OF_DAY, 14);
alarmMgr.setInexactRepeating(AlarmManager.RTC, calendar.getTimeInMillis(),
AlarmManager.INTERVAL_DAY, alarmIntent);
Question:
Where in my phone can I see this alarm registered? I looked in the Clock -> Alarm but I do not see it.
I just want to see it so I know it has been setup correctly.
Where in my phone can I see this alarm registered? I looked in the Clock -> Alarm but I do not see it.
I think you've got a wrong idea about the concept of AlarmManager :
AlaramManager is an android system component allowing you (as a developer) to schedule execution of one of the three:
1) start service
2) send broadcast
3) start activity.
one of the best thing is that your app don't have to be running at all. instead, the the OS will wake up your process if your application scheduled with the AlaramManager any alarm for this time, and start the service/activity/broadcast based on when you specified..
Registering an alarm in Android, where does it go?
the pendingIntent object you provided to the alramManager is saved by the system, in order to execute it at the right time.
there is no any system UI component that shows you that visually!! and there is not make sense that there will be such, because - app can schedule alarms for any kind of reasons that most of them not directly been visualized to the user.
for example: my app schedule alram each two hours, in order to update in front of my company servers, the local database of my app. this action don't involved any interaction from the user, and happens completely in background.
after understanding that, I can tell you that there is way to check programatically what scheduled alarms your app have in front of the AlaramManager: follow this answer: How to check if AlarmManager already has an alarm set?
for more information, I strongly recommends you to read the documention of PendingIntent , and AlaramManager:
http://developer.android.com/reference/android/app/AlarmManager.html
http://developer.android.com/reference/android/app/PendingIntent.html
You can do it by using ADB. From the ADB console within Android Studio try the following:
adb shell dumpsys alarm
This should show you all of the alarms that have been set, as well as their details, such as alarm time, interval, etc.

How to start a notification at a specified time every day?

I am a new developer and don't know much about android programming. I am trying to make an app that reminds a user to do a particular thing every day at a specific time (like going to gym at 5:30 pm). I am able to get a notification after clicking of a button but i want this to be done by the app i.e. even if the app is not running it will remind me everyday to go the gym at 5:30. How can I get this???
I tried using AlarmManager but it gives my notification at that time only and sets the alarm for the specified time.
Set repeating alarm. on broadcast receiver start your notification

Android: Calendar integration with custom notifications

I need to integrate, in my android application, a calendar from which i can set new event.
I know that is possible call the android calendar (using intent), but what I need is slightly different, for this reason:
I need that when the time of the event is reached, some code is started, and no default notification occurs! In other words I want create a custom notification when alarm of event goes off. Maybe I need to use AlarmManager
How can I solve this problem?
If your problem is that you need to launch some kind of intent at a specified time then you can use AlarmManager. It allows you to schedule your application to be run at some point. When an alarm goes off, the Intent that had been registered for it is broadcast by the system.
For More information about AlarmManager, you can check this link : AlarmManager

How to use Android Built-in Alarm to integrate my alarm app?

I want to create my alarm app.
but, I don't want to re-design a new alarm clock function.
so, I want to use android built-in alarm clock.
what I want the procedure is:
use android built-in alarm clock to set the time.
when the alarm is ring, my alarm app will be launched to replace built-in one.
use my alarm app to dismiss the alarm.
How could I make it?
Thank you so much.
How could I make it?
You can't. The only thing an SDK app can do with respect to the device's own alarm clock app is to display an activity to allow the user to set the alarm, with a filled-in set of values.

how to get notification of Alarm which is passed in between switchoff to switched on mobile

Hi
I am developing a application in which i am using AlarmManager
Problem
When i set pending Intent using Alarm manager on perticular date and time its work fine
but suppose i set alarm time on date 30-05-2011 and time 10:00 AM and suppose current time is date 30-05-2011 and time 09:50 AM
and now after creating pending intent i switched off my device and after 10:01 AM i starts my device
at that time i expect notification for 10:00 AM alarm but i am not getting it
Any idea how i can get notification After switch on my mobile
Through AlarmManager, you can only wake up your device when it is sleeping.
To do that use
setRepeating(int type, long triggerAtTime, long interval, PendingIntent operation)
or set(...)
with RTC_WAKEUP or ELAPSED_REALTIME_WAKEUP
But it doesn't work with a device at off.
So you should consider having your alarms in a database, along with the last time your app was on, and count the alarms you missed since last time you were up.
Regards,
Stéphane
If you read the AlarmManager API doc page:
Registered alarms are retained while the device is asleep (and can optionally wake the device up if they go off during that time), but will be cleared if it is turned off and rebooted.
As an alternative, you can register a broadcast receiver for the intent android.intent.action.BOOT_COMPLETED and check your SharedPreferences if you need to perform an action.
See this question for details about the broadcast: Trying to start a service on boot on Android

Categories

Resources