我对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);
}
我用这个 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);
}
这够了吗??