确实,即使重启后报警管理器持续?

编程入门 行业动态 更新时间:2024-10-15 14:20:05
本文介绍了确实,即使重启后报警管理器持续?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我是真正的新机器人,我一直在研究有关的报警。我想报警,如果有那一天生日。我已经使用报警管理。我很困惑,因为我已阅读,它重新启动后会清除。我这样做,我只是用模拟器没有一款Android手机。

I am really new to android, I have been researching about alarms. I want to alarm if there is a birthday on that day. I've have used alarm manager. I was confused because i have read that it clears after reboot. I don't have an android phone so I'm just using the emulator.

下面是我的code:

public void schedAlarm() { AlarmManager am = (AlarmManager) getSystemService(ALARM_SERVICE); Intent intent = new Intent(this, AlarmService.class); pendingIntent = PendingIntent.getBroadcast(this, contact.id, intent, PendingIntent.FLAG_ONE_SHOT); am.setRepeating(AlarmManager.RTC, timetoAlarm, nextalarm, pendingIntent); }

我提出这个BroadcastRecever在替换为AlarmSerivce 这里:

I made this BroadcastRecever in replace for AlarmSerivce Here :

public void onReceive(Context context, Intent intent) { nm = (NotificationManager) context.getSystemService(Context.NOTIFICATION_SERVICE); CharSequence from = "It Birthday!"; CharSequence message =" Greet your friend."; PendingIntent contentIntent = PendingIntent.getActivity(context, 0, new Intent(), 0); Notification notif = new Notification(R.drawable.ic_launcher, "Birthday", System.currentTimeMillis()); notif.setLatestEventInfo(context, from, message, contentIntent); nm.notify(1, notif); }

这是不够??

is this enough??

推荐答案

一个简单的答案是否。但是,是的,你可以通过创建实现这一的BroadcastReceiver 将启动报警,同时启动装置完成。

A simple answer would be NO. But yes you can achieve this by creating a BroadCastReceiver which will start the Alarm while booting completes of the device.

使用<作用机器人:名称=android.intent.action.BOOT_COMPLETED/> 诱捕启动活动的BroadcastReceiver类

Use <action android:name="android.intent.action.BOOT_COMPLETED" /> for trapping boot activity in BroadCastReceiver class.

您需要添加上面一行在AndroidManifest.xml中有:

You need to add above line in AndroidManifest.xml as follows,

<receiver android:name=".AutoStartUp" android:enabled="true" android:exported="false" android:permission="android.permission.RECEIVE_BOOT_COMPLETED"> <intent-filter> <action android:name="android.intent.action.BOOT_COMPLETED" /> </intent-filter> </receiver>

更多推荐

确实,即使重启后报警管理器持续?

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

发布评论

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

>www.elefans.com

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