detect default alarm clock application alarms

后端 未结 5 2025
深忆病人
深忆病人 2021-02-20 18:34

I would like to know if there is a way (probably a system broadcast) to know that the alarm clock default application is now start ringing.

if not - I\'ll be satisfied a

相关标签:
5条回答
  • 2021-02-20 19:04

    Hi looks like I am little late to the party but anyways here is what i could dig.

    1.) A system broadcast to know that the alarm clock default application is now start ringing.

    I checked ADB logs from my Note3 , i could see this log whenever default alarm rings "I/SecExternalDisplayIntents_Java(2797): Intent Recieved .. - com.samsung.sec.android.clockpackage.alarm.ALARM_STARTED_IN_ALERT BroadCast Map value - 7"

    I tried catching the intent with action name "com.samsung.sec.android.clockpackage.alarm.ALARM_STARTED_IN_ALERT" successfully. Though I highly doubt if this intent be avialable across all android devices.

    The package name of intent action gave me further hints and i found the answer to

    2.)I'll be satisfied also if I could get progrematically list of all active alarms been set by the user

    seems the clockpackage exposes a Content provider at "com.samsung.sec.android.clockpackage/alarm" location i could query all the alarms set by user from this DB( enabled /disabled/name/snooze details etc ).

    By toggling the enable/disable button i figured the value for a the alarm been on/off is in column no 1(columns start from 0 index). Incase you want more data i would suggest pulling the DB and viewing the table structure in SQlite DB browser (device may have to be rooted to pull the entire DB).

    Similar DB must exist on other android devices as well (I broke my nexus else could have tested on that as well ) cheers

    0 讨论(0)
  • 2021-02-20 19:08

    If I understand you right, you want to check which applications use the Alarm Manager class, If that is the case then you can do it by allowing your application to monitor the log cat, once done you will definitely get to know which applications are using alarm. At-least this should work at boot time. You can create a new thread to running the logcat(without the option -d) in the background. Also make sure that you are adding the required permissions in the Manifest for this to work.

    Screen-shot of boot time:

    enter image description here

    Update: LogCat after setting an Alarm for 9:56pm using the default system clock

    After coming to know of OP's requirements through an update in the original question, I tried to set an alarm for a specific time and checked LogCat for the same time and the result is logged below with time details and events in chronological order:

    enter image description here

    This might be of interest as well

    0 讨论(0)
  • 2021-02-20 19:09

    I highly doubt that you'll find a solution for this.

    Alarms are maintained by AlarmManagerService. Since it is not included in the SDK, reflection might be the only way to get something out of it. But from the looks of it, even reflection cannot help you here:

    • Need access to AlarmManagerService $ Batch # alarms <--- ArrayList< Alarm >
    • Need access to AlarmManagerService # mAlarmBatches <--- ArrayList< Batch >
    • Use reflection:
      • Class< ? > ams = Class.forName("com.android.server.AlarmManagerService")
      • Field mAlarmBatches = ams.getDeclaredField("mAlarmBatches")
      • Object listOfBatches = mAlarmBatches.get(????)
      • Stuck

    Seems like a dead end to me. You cannot instantiate AlarmManagerService - not even by accessing and invoking its constructor (because it calls a native method).

    Another line of reasoning: Here's a look at AlarmManagerService$Alarm class:

    public static class Alarm {
        public int type;
        public int count;
        public long when;
        public long windowLength;
        public long whenElapsed;    // 'when' in the elapsed time base
        public long maxWhen;        // also in the elapsed time base
        public long repeatInterval;
        public PendingIntent operation;  <<<<<<============Problem==============
        public WorkSource workSource;
    
        ....
        ....
    }
    

    If one can gain access to the PendingIntent, what's stopping them from cancelling alarms at will - alarms that have been set by other apps?

    Still, I hope someone here can help you out.

    Link: AlarmManagerService

    0 讨论(0)
  • 2021-02-20 19:13

    You can't query AlarmManager for a list of commands which is what you would need to do to achieve this.

    The closest you can get to finding a list of alarms would be to use dumpsys adb shell dumpsys alarm, but obviously you can't do that in code.

    0 讨论(0)
  • 2021-02-20 19:27

    The default clock app - com.android.deskclock - has a ClockProvider that supports queries,
    but unfortunately, it's not exported so it cannot be used by third party apps.

    0 讨论(0)
提交回复
热议问题