安卓:为什么系统重启后没有报警通知停止

编程入门 行业动态 更新时间:2024-10-20 07:52:56
本文介绍了安卓:为什么系统重启后没有报警通知停止的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我开发一个Android应用程序,应该火灾报警一天五次: - 时代的每一天不是恒定的 - 报警触发后,我会安排一个报警

我的问题是:报警通知工作1天,然后停止,并在设备重启两次通知不工作,我不知道现在是否有另一种方式来做到这一点,任何帮助将是非常AP preciated!

code: 我有这个函数来调用广播reciever

公共静态无效Start_Notifying(上下文的背景下){     日历CAL = Calendar.getInstance();     cal.setTimeInMillis(System.currentTimeMillis的());     cal.add(Calendar.HOUR_OF_DAY,小时);     cal.add(Calendar.MINUTE,分钟);     意向意图=新的意图(背景下,OnetimeAlarmReceiver.class);     intent.setAction(START_NOTIFYING);     PendingIntent pendingIntent = PendingIntent.getBroadcast(背景下,notify.REQUEST_ code,意向,0);     AlarmManager alarmManager =(AlarmManager)context.getSystemService(ALARM_SERVICE);     alarmManager.set(AlarmManager.RTC_WAKEUP,cal.getTimeInMillis(),pendingIntent);     SaveAlarmManager(alarmManager,pendingIntent); }

oneTimeAlarmReciever的code

公共无效的onReceive(上下文的背景下,意图意图){     main_menu.con =背景;     通知notifyDetails;     NotificationManager纳米=(NotificationManager)context.getSystemService(Context.NOTIFICATION_SERVICE);     notifyDetails =新的通知(R.drawable.icon,S1,System.currentTimeMillis的());     PendingIntent pendingIntent = PendingIntent.getActivity(背景下,REQUEST_ code,新的意向(背景下,prayertimes.class),0);     notifyDetails.setLatestEventInfo(上下文,S2 + notify.prayName,S3,pendingIntent);     notifyDetails.sound = Uri.parse(PlaySound());     nm.notify(NOTIFICATION_ID,notifyDetails);     main_menu.notify_me(); }

notify_me的code()

静态无效notify_me(){     小时= pTime.num1;     分= pTime.num2;     Start_Notifying(CON); }

在清单文件

<使用-权限的Andr​​oid:名称=android.permission.RECEIVE_BOOT_COMPLETED>< /使用-许可> <接收器类=机器人OnetimeAlarmReceiver。:NAME =OnetimeAlarmReceiver>     <意向滤光器>         <作用机器人:名称=START_NOTIFYING/>         <作用机器人:名称=android.intent.action.BOOT_COMPLETED> < /作用>         <数据机器人:MIMETYPE =音频/ OGG/>     &所述; /意图滤光器> < /接收器>

解决方案   

为啥系统重新启动后报警通知停止

由于报警时间表清零重新启动。如果你想你的报警器重新启动后再次回升,则需要实施的BroadcastReceiver 的响应 RECEIVE_BOOT_COMPLETED 播出。该演示/ 在我的 WakefulIntentService 回购说明了这一点。

I am developing an android application that should fire an alarm five times a day: - the times in each day is not constant - after the alarm is fired I will schedule the next alarm.

My problem is : the alarm notification works for 1 day then it stops and also when the device is rebooted twice the notification doesn't work , I don't now if there is another way to do that , any help will be very appreciated!

Code: I have this function to call the broadcast reciever

public static void Start_Notifying(Context context){ Calendar cal = Calendar.getInstance(); cal.setTimeInMillis(System.currentTimeMillis()); cal.add(Calendar.HOUR_OF_DAY,hour); cal.add(Calendar.MINUTE, min); Intent intent = new Intent(context, OnetimeAlarmReceiver.class); intent.setAction("START_NOTIFYING"); PendingIntent pendingIntent = PendingIntent.getBroadcast(context, notify.REQUEST_CODE, intent,0); AlarmManager alarmManager = (AlarmManager) context.getSystemService(ALARM_SERVICE); alarmManager.set(AlarmManager.RTC_WAKEUP, cal.getTimeInMillis() , pendingIntent); SaveAlarmManager(alarmManager, pendingIntent); }

the code of oneTimeAlarmReciever

public void onReceive(Context context, Intent intent) { main_menu.con = context; Notification notifyDetails; NotificationManager nm = (NotificationManager)context.getSystemService(Context.NOTIFICATION_SERVICE); notifyDetails = new Notification(R.drawable.icon,s1,System.currentTimeMillis()); PendingIntent pendingIntent = PendingIntent.getActivity(context, REQUEST_CODE, new Intent(context, prayertimes.class), 0); notifyDetails.setLatestEventInfo(context,s2+ notify.prayName , s3, pendingIntent); notifyDetails.sound=Uri.parse(PlaySound()); nm.notify(NOTIFICATION_ID, notifyDetails); main_menu.notify_me(); }

The code of notify_me()

static void notify_me() { hour =pTime.num1; min =pTime.num2; Start_Notifying(con); }

In the manifest file

<uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED"></uses-permission> <receiver class =".OnetimeAlarmReceiver" android:name="OnetimeAlarmReceiver"> <intent-filter> <action android:name="START_NOTIFYING" /> <action android:name="android.intent.action.BOOT_COMPLETED"> </action> <data android:mimeType="audio/ogg" /> </intent-filter> </receiver>

解决方案

why did the Alarm notification stop after system reboot

Because alarm schedules are cleared on a reboot. If you want to have your alarms pick up again after a reboot, you will need to implement a BroadcastReceiver that responds to the RECEIVE_BOOT_COMPLETED broadcast. The demo/ project in my WakefulIntentService repo demonstrates this.

更多推荐

安卓:为什么系统重启后没有报警通知停止

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

发布评论

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

>www.elefans.com

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