确实,即使重启后报警管理器持续? [英] does Alarm Manager persist even after reboot?

查看:119
本文介绍了确实,即使重启后报警管理器持续?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

这篇关于确实,即使重启后报警管理器持续?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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