Android:闹钟完成或消失后打开活动 [英] Android: open activity when alarm clock is done or dismmised

查看:124
本文介绍了Android:闹钟完成或消失后打开活动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

用户通过电话备用时钟设置的每个闹钟都有一个选项,可以在闹钟被取消或结束时打开另一个应用程序(我不确定棉花糖中是否添加了此功能,但是我有它并且运行android M)。

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);


推荐答案

因此,似乎没有选择添加您的应用程序到所需的列表,使用户可以选择解除或发出警报后立即打开的应用程序。

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.

我有LG手机,所以我的事件是 com.lge.clock.alarmalert .stop ,但您必须弄清楚每台设备的事件是什么。我见过与类似的主题这个

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.

接收方:

@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
    }
}

这篇关于Android:闹钟完成或消失后打开活动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆