问题是警报延迟约1-2分钟。但始终有效。所以时间不完全是。我读了很多关于这个问题的书。在Play市场上找到应用程序额外警报(它需要一些特殊规则android.permission.ACCESS_NOTIFICATION_POLICY,但不知道它应如何影响确切的时间唤醒)。它可以在我的设备上正常播放(Android 8.0 Honor 7 Pro)。因此,有一种方法可以做到这一点。但是如何?
我尝试过:
1)接收者android:name =“。receivers.AlarmReceiver” android:process =“:remote” android:process =“:remote”
2)尝试使用setExactAndAllowWhileIdle。一样-计时器不精确。 可能是什么?像主要意图之前的预先意图还是其他意图? 有任何想法吗?)不要使用AlarmManager吗?预定了什么?
我有: AlarmHelper类:
long firstAlarm = 1639534528996l;
Calendar calendar = Calendar.getInstance();
calendar.setTimeInMillis(alarm.getTime());
if (calendar.getTimeInMillis() < System.currentTimeMillis()) {
calendar.add(Calendar.DAY_OF_YEAR, 1);
}
Intent myIntent = new Intent(App.getInstance().getApplicationContext(), AlarmReceiver.class);
final Bundle bundle = new Bundle();
bundle.putByteArray(Alarm.TAG, Parcelables.toByteArray(alarm));
myIntent.putExtras(bundle);
AlarmManager alarmManager = (AlarmManager) App.getInstance().getApplicationContext().getSystemService(Context.ALARM_SERVICE);
PendingIntent pendingIntent = PendingIntent.getBroadcast(App.getInstance().getApplicationContext(), (int) calendar.getTimeInMillis(), myIntent, PendingIntent.FLAG_UPDATE_CURRENT);
if (set) {
alarmManager.setAlarmClock(new AlarmManager.AlarmClockInfo(calendar.getTimeInMillis(), pendingIntent), pendingIntent);
} else {
alarmManager.cancel(pendingIntent);
}
firstAlarm = calendar.getTimeInMillis();
和AlarmReceiver:
public void onReceive(Context context, Intent intent) {
Intent intentNew = new Intent(App.getInstance().getApplicationContext(), AlarmActivity.class);
final Bundle bundle = intent.getExtras();
intentNew.putExtra(Alarm.TAG, bundle.getByteArray(Alarm.TAG));
intentNew.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP);
context.startActivity(intentNew);
}