Android: open activity when alarm clock is done or dismmised

落花浮王杯 提交于 2019-12-02 10:33:45
Juvi

So it seems that there's no option to add your app to the desired list which allow the user to pick an application to open immediately after the alarm has been dismissed or done.

My other solution is to listen to that specific event of dismissing or done through broadcast receiver. This might be a bit tricky because the event has multiple names according to the device.

I have LG phone so my event is com.lge.clock.alarmalert.stop, but you'll have to figure out whats the event for each device. I've seen some similar topics as this one.

Here's my manifest declaration for the receiver:

<receiver android:name=".Receiver.AlarmBroadcastReceiver">
    <intent-filter>
        <action android:name="com.android.deskclock.ALARM_DISMISS" />
        <action android:name="com.android.deskclock.ALARM_DONE" />
        <action android:name="com.lge.clock.alarmalert.stop" />
    </intent-filter>
</receiver>

The deskclock is the default stock clock running on some devices, as I mentioned, I had to find the action for the LG phones and added it aswell.

The Receiver:

@Override
public void onReceive(Context context, Intent intent) {
    String action = intent.getAction();
    if (action.equals("com.android.deskclock.ALARM_DISMISS") || action.equals("com.android.deskclock.ALARM_DONE") || action.equals("com.lge.clock.alarmalert.stop"))
    {
        ////Do Something
    }
}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!