6.0 和4.4 是分界点,想要闹钟精确,根据不同版本不同处理
long l = SystemClock.elapsedRealtime();
AlarmManager am = (AlarmManager) getSystemService(ALARM_SERVICE);
Intent i = new Intent(this, CheckTinkerUpdateService.class);
PendingIntent pi = PendingIntent.getService(this, 0, i, 0);
if (am != null) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
am.setExactAndAllowWhileIdle(AlarmManager.ELAPSED_REALTIME_WAKEUP, l+ TIME_INTERVAL, pi);
} else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
am.setExact(AlarmManager.ELAPSED_REALTIME_WAKEUP, l+ TIME_INTERVAL, pi);
} else {
am.set(AlarmManager.ELAPSED_REALTIME_WAKEUP, l+ TIME_INTERVAL, pi);
}
}