Created
July 1, 2024 10:38
-
-
Save sajjadyousefnia/5921dc1e29991384348854012e68aafd to your computer and use it in GitHub Desktop.
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
import android.content.Context | |
import android.content.Intent | |
import android.os.PowerManager | |
import android.provider.Settings | |
import android.net.Uri | |
fun requestIgnoreBatteryOptimizations(context: Context) { | |
val powerManager = context.getSystemService(Context.POWER_SERVICE) as PowerManager | |
val packageName = context.packageName | |
if (!powerManager.isIgnoringBatteryOptimizations(packageName)) { | |
val intent = Intent(Settings.ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS) | |
intent.data = Uri.parse("package:$packageName") | |
context.startActivity(intent) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment