0

Every alarm clock that the user set through the phone stock clock has an option of opening another application when the alarm is dismissed or done (I'm not sure if this feature is added in Marshmallow but I have it and I run android M).

The default for each alarm is "none" but you're able to pick the mail, weather, music applications etc... I would like to add my application to this list so it'll open directly when the alarm is done.

What settings are needed for my application to show up at this list, and how can I set it as the default app for specific alarm (What extra should be specefied)

Intent i = new Intent(AlarmClock.ACTION_SET_ALARM);
i.putExtra(AlarmClock.EXTRA_MESSAGE, "New Alarm");
i.putExtra(AlarmClock.EXTRA_HOUR, 10);
i.putExtra(AlarmClock.EXTRA_MINUTES, 30);
startActivity(i);
Juvi
  • 1,078
  • 1
  • 19
  • 38
  • AlarmClock.ACTION_SET_ALARM is used to set the alarm for a given time of day, not to open another activity when the alarm is dismissed. What is it you concisely want to achieve? – Piyush Mar 12 '16 at 12:38
  • I described the goal in the question - I want to open an activity immediately when the alarm is done or dismissed. There's a native feature for that (might be added in android M but i'm not sure), that you can pick a specific app to open when the alarm is done and I want to add my app to this list. – Juvi Mar 12 '16 at 12:43
  • "I want to open an activity immediately when the alarm is done or dismissed." This requires an alarm to be set from the application in the first place. If you to call your activity when the alarm from the stock clock goes off, there is no native feature for this currently. – Piyush Mar 12 '16 at 12:57
  • I wouldn't go with things like "it's not possible", my second approach is to listen with broadcast receiver to the dismiss or done events.. – Juvi Mar 12 '16 at 14:17

1 Answers1

0

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
    }
}
Community
  • 1
  • 1
Juvi
  • 1,078
  • 1
  • 19
  • 38