detect default alarm clock application alarms

后端 未结 5 2035
深忆病人
深忆病人 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: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

提交回复
热议问题