REQUEST_IGNORE_BATTERY_OPTIMIZATIONS Dialog

How to disable doze mode in android, kotlin?

To disable doze mode in an Android device, you can follow these steps:

  1. Open the Settings app on your Android device.
  2. Scroll down and tap on the “Battery” or “Battery & performance” option.
  3. Tap on the “Battery optimization” option.
  4. Tap on the “Not optimized” drop-down menu and select “All apps”.
  5. Scroll down and find the app for which you want to disable doze mode.
  6. Tap on the app and select “Don’t optimize”.

Alternatively, you can disable doze mode for specific apps by using the following code in Kotlin:

val powerManager = getSystemService(Context.POWER_SERVICE) as PowerManager
val packageName = "com.example.myapp"
val packageIntent = packageManager.getPackageInfo(packageName, 0)
powerManager.setPowerSaveMode(false)
powerManager.setDozeWhitelistApp(packageIntent.packageName, true)

Note that this code is intended for use in an Activity class. You may need to modify it slightly depending on your specific use case. Additionally, keep in mind that disabling doze mode can have negative effects on battery life, so it should only be done if absolutely necessary.

Mobile Application Developer with over 12 years of experience crafting exceptional digital experiences.I specialize in delivering high-quality, user-friendly mobile applications across diverse domains including EdTech, Ride Sharing, Telemedicine, Blockchain Wallets, and Payment Gateway integration.My approach combines technical expertise with collaborative leadership, working seamlessly with analysts, QA teams, and engineers to create scalable, bug-free solutions that exceed expectations.Let's connect and transform your ideas into remarkable mobile experiences.
0 0 votes
Article Rating

Leave a Reply

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments