我创建了一个提醒系统,它正常工作,当我关闭它运行的应用程序时。但是当我通过关闭所有最近的应用程序来销毁应用程序时,警报管理器不会唤醒应用程序,这是我的代码:
清单:
<receiver android:name=".TimeAlarm" />
方法:
public void addAlarm(int id, int year, int month, int day, int hour, int minute) {
Calendar cal = Calendar.getInstance();
cal.set(year, month, day, hour, minute);
Intent intent = new Intent(this, TimeAlarm.class);
PendingIntent operation = PendingIntent.getBroadcast(this, id, intent, PendingIntent.FLAG_ONE_SHOT);
am.set(AlarmManager.RTC_WAKEUP, cal.getTimeInMillis(), operation);
}
班主任:
public class TimeAlarm extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
int notificationID = 3;
NotificationManager notificationManager;
Notification myNotification;
Intent myIntent = new Intent(context, MainActivity.class);
PendingIntent pendingIntent = PendingIntent.getService(context, 0, intent, 0);
myNotification = new NotificationCompat.Builder(context)
.setContentTitle("Exercise of Notification!")
.setContentText("Do Something...")
.setTicker("Notification!")
.setWhen(System.currentTimeMillis())
.setContentIntent(pendingIntent)
.setDefaults(Notification.DEFAULT_SOUND)
.setAutoCancel(true)
.setSmallIcon(R.drawable.ics_close)
.build();
notificationManager = (NotificationManager)context.getSystemService(Context.NOTIFICATION_SERVICE);
notificationManager.notify(notificationID, myNotification);
}
}
谢谢!