Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

精确闹钟 #1235

Open
imndx opened this issue Mar 27, 2024 · 0 comments
Open

精确闹钟 #1235

imndx opened this issue Mar 27, 2024 · 0 comments

Comments

@imndx
Copy link
Contributor

imndx commented Mar 27, 2024

Android 13之后,对精确闹钟的限制越来越严格,只允许特定类型的应用使用,是否有其他方案?

private static PendingIntent setAlarmMgr(final long id, final long time, final Context context) {
final AlarmManager am = (AlarmManager) context.getSystemService(Context.ALARM_SERVICE);
if (am == null) {
Log.e(TAG, "am == null");
return null;
}
Intent intent = new Intent();
intent.setAction("ALARM_ACTION(" + String.valueOf(Process.myPid()) + ")");
intent.putExtra(KEXTRA_ID, id);
intent.putExtra(KEXTRA_PID, Process.myPid());
PendingIntent pendingIntent;
if (Build.VERSION.SDK_INT < 23) {
pendingIntent = PendingIntent.getBroadcast(context, (int) id, intent, PendingIntent.FLAG_CANCEL_CURRENT);
} else {
pendingIntent = PendingIntent.getBroadcast(context, (int) id, intent, PendingIntent.FLAG_CANCEL_CURRENT | PendingIntent.FLAG_IMMUTABLE);
}
if (Build.VERSION.SDK_INT < 19) { //KITKAT
am.set(AlarmManager.ELAPSED_REALTIME_WAKEUP, time, pendingIntent);
} else {
am.setExact(AlarmManager.ELAPSED_REALTIME_WAKEUP, time, pendingIntent);
}
return pendingIntent;
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant