我正在设置重复闹钟 -
A1
警报在广播接收器中重置为 -
int intervalTime = 5 * 1000;
Intent i = new Intent(context, OnSingleAlarmReceiver.class);
PendingIntent pi = PendingIntent.getBroadcast(context, 1111,
i, 0);
AlarmManager mgr = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
AlarmManager.AlarmClockInfo alarmClockInfo = new AlarmManager.AlarmClockInfo(System.currentTimeMillis() + intervalTime, pi);
mgr.setAlarmClock(alarmClockInfo, pi);
} else if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.KITKAT) {
mgr.setRepeating(AlarmManager.RTC_WAKEUP,
System.currentTimeMillis() + intervalTime,
intervalTime,
pi);
} else {
mgr.setExact(AlarmManager.RTC_WAKEUP,
System.currentTimeMillis() + intervalTime,
pi);
}
}
广播接收器在清单中正确添加,如 -
public class OnSingleAlarmReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
resetAlarm(context);
}
private void resetAlarm(Context context) {
if (android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSION_CODES.KITKAT) {
// Calling same function to re set alarm
}
}
它几乎适用于所有手机......
但是在联想Vibe中没有型号 - 联想P1ma40和操作系统版本5.1,当我从任务管理器(运行应用程序)中删除应用程序时,警报被杀/被删除。为什么会这样?我怎么能阻止它?
先谢谢