手机关闭时的警报管理器

编程入门 行业动态 更新时间:2024-10-27 06:33:42
本文介绍了手机关闭时的警报管理器 - ANDROID的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在做一个闹钟系统,但我在手机关机时遇到了问题..闹钟不起作用..

I'm doing an alarm System but i've a problem when the phone is turned off.. The alarm doesn't work..

我正在按如下方式设置警报:

I'm setting de alarm as follows:

public void doIntents(Context context, long milis, Tratam trat){ cal=Calendar.getInstance(); alarmManager = (AlarmManager) context.getSystemService(Service.ALARM_SERVICE); cal.setTimeInMillis(milis); Intent intent = new Intent(context, OnAlarmReceiver.class); pendingIntent = PendingIntent.getBroadcast(context, trat.getId(), intent, PendingIntent.FLAG_UPDATE_CURRENT); alarmManager.set(AlarmManager.RTC_WAKEUP,milis ,pendingIntent); }

当手机打开时,闹钟工作正常..

The Alarm works Ok when the phone is turned on..

我能做什么?

谢谢!

推荐答案

是的,问题是手机重启时你的应用没有运行.您需要注册一个可以接收 BOOT_COMPLETED 消息的 BroadcastReceiver,以便在手机重启时接收消息.然后在 BroadcastReceiver 中,您可以重新安排这些警报或其他任何内容.但我不认为你可以做任何事情来让手机关机时触发闹钟..(例如打开手机)

Yea, the problem is your app isn't running when the phone restarts. You'll need to register a BroadcastReceiver that can receive the BOOT_COMPLETED message so it receives a message when the phone reboots. Then in the BroadcastReceiver you can either reschedule those alarms or whatever. But I don't think there's anything you can do about making your alarm trigger when the phone is off..(e.g. making the phone turn on)

<receiver android:name="MyBootReceiver" android:enabled="true" android:exported="true" android:label="BootReceiver"> <intent-filter> <action android:name="android.intent.action.BOOT_COMPLETED"></action> </intent-filter> </receiver>

更多推荐

手机关闭时的警报管理器

本文发布于:2023-11-27 04:41:52,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1636638.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:管理器   警报   手机

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!