Created
December 30, 2023 13:44
-
-
Save kishan-vadoliya/153a6a57ad11dbb7575d09f358146b49 to your computer and use it in GitHub Desktop.
Set Exact Alarm in Android 13 and above
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" /> | |
<uses-permission android:name="com.huawei.permission.external_app_settings.USE_COMPONENT" /> | |
<uses-permission android:name="oppo.permission.OPPO_COMPONENT_SAFE" /> | |
<uses-permission android:name="com.google.android.finsky.permission.BIND_GET_INSTALL_REFERRER_SERVICE" /> | |
val receiver = ComponentName(context, AlarmReceiver::class.java) | |
context.packageManager.setComponentEnabledSetting( | |
receiver, | |
PackageManager.COMPONENT_ENABLED_STATE_DISABLED, | |
PackageManager.DONT_KILL_APP | |
) | |
fun Context.openExactAlarmSettingPage() { | |
val manager = getSystemService(Context.ALARM_SERVICE) as AlarmManager | |
Log.d("TestData","Utils openExactAlarmSettingPage :${manager.canScheduleExactAlarms()}") | |
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) { | |
val alarmManager = ContextCompat.getSystemService(this, AlarmManager::class.java) | |
if (alarmManager?.canScheduleExactAlarms() == false) { | |
Intent().also { intent -> | |
intent.action = Settings.ACTION_REQUEST_SCHEDULE_EXACT_ALARM | |
startActivity(intent) | |
} | |
} | |
} | |
} | |
fun Context.isScheduleExactAlarm() :Boolean { | |
val manager = getSystemService(Context.ALARM_SERVICE) as AlarmManager | |
val alarmManager = ContextCompat.getSystemService(this, AlarmManager::class.java) | |
return alarmManager?.canScheduleExactAlarms()!! | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment