0

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.

Ziem
  • 6,579
  • 8
  • 53
  • 86
andrewb
  • 2,995
  • 7
  • 54
  • 95

2 Answers2

1

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

Community
  • 1
  • 1
Tal Kanel
  • 10,475
  • 10
  • 60
  • 98
0

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.

Willis
  • 5,308
  • 3
  • 32
  • 61
  • Where is the ADB console within Android Studio? – andrewb Apr 23 '15 at 17:07
  • My mistake I though that ADB comes with Android Studio but it does not. You can just run ADB separately Here is more info on ADB: http://developer.android.com/tools/help/adb.html. Should you wish to integrate it with Android Studio you can: http://android.stackexchange.com/questions/69108/how-to-start-root-shell-with-android-studio – Willis Apr 23 '15 at 17:11
  • I would suggest just trying the above command in the standalone ADB console before you try and integrate it. – Willis Apr 23 '15 at 17:11
  • Hmm okay. So I ran code to set an alarm for 11am (my timezone) and nothing happened on my device. Is my code correct? – andrewb Apr 23 '15 at 17:12
  • Did you wait a few minutes? Since you used the `setInexactRepeating` method your alarm is not guaranteed to trigger exactly at the top of the hour. According to the API: "Schedule a repeating alarm that has inexact trigger time requirements; for example, an alarm that repeats every hour, but not necessarily at the top of every hour." – Willis Apr 23 '15 at 17:16
  • I set it to go at 11am, so I presume it could go anywhere from 11:00 to 11:59 ? – andrewb Apr 23 '15 at 17:17
  • I believe so yes, Check here for more information on the `AlarmManager` class, along with some examples: https://developer.android.com/reference/android/app/AlarmManager.html – Willis Apr 23 '15 at 17:18
  • The adb command produces a lot of output, anywhere to filter based on package name/something? – andrewb Apr 23 '15 at 17:28
  • This is possible, check here: http://stackoverflow.com/questions/6854127/filter-logcat-to-get-only-the-messages-from-my-application-in-android – Willis Apr 23 '15 at 18:04