小编Xel*_*mae的帖子

报警管理器即使在重启后仍然存在?

我是android的新手,我一直在研究警报.如果当天有生日,我想报警.我已经使用了报警管理器.我很困惑因为我已经读过它在重启后会清除.我没有Android手机,所以我只是使用模拟器.

这是我的代码:

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);
}
Run Code Online (Sandbox Code Playgroud)

我将这个BroadcastRecever替换为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);
 }
Run Code Online (Sandbox Code Playgroud)

这够了吗??

android alarmmanager android-alarms

47
推荐指数
2
解决办法
3万
查看次数

标签 统计

alarmmanager ×1

android ×1

android-alarms ×1