Trigger code when alarm from Clock-application starts in Android
Is there anyway to trigger some code when the Alarm in the clock-application is executed? I read about the Alarm Manager but its only for creating your own alarms.
I guess you will never be sure if the clock-applicat开发者_运维知识库ion exists on the device. But if it does I would like to get notified.
/Br Johannes
Warning: You are trying to get a notification about a Clock's state. This app is not part of official Android SDK: the solution below is not supported (or recommended) by Google and subject to change without notice.
Take a look at the source code od DeskClock (a new name for AlarmClock). Specifically take a look at it's AndroidManifest.xml.
It seems that it receives com.android.deskclock.ALARM_ALERT
:
<receiver android:name="AlarmReceiver">
<intent-filter>
<action android:name="com.android.deskclock.ALARM_ALERT" />
<action android:name="alarm_killed" />
<action android:name="cancel_snooze" />
</intent-filter>
</receiver>
Try registering this receiver in your app.
精彩评论