Categories: androidbeginnerkotlin

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.

Saiful Alam Rifan

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.

Recent Posts

What’s New in Jetpack Compose 1.8: Autofill, Text, Visibility & More (2025)

Jetpack Compose 1.8 rolls out handy features like Autofill integration, slick Text enhancements including auto-sizing… Read More

2 weeks ago

Reified Keyword in Kotlin Explained: Unlock Type Safety

 Reified Keyword in Kotlin: Simplify Your Generic Functions Kotlin's reified keyword lets your generic functions know the… Read More

2 weeks ago

Android Studio Cloud: Develop Android Apps Anywhere (2025)

Android Studio Cloud: Ditch the Setup, Code Anywhere (Seriously!) Alright, fellow Android devs, gather 'round… Read More

2 weeks ago

Firebase Studio & Google’s AI Dev Tools Guide

Firebase Studio is a new cloud-based platform for building AI-powered apps, launched at Google Cloud… Read More

3 weeks ago

Kotlin Multiplatform Future: Trends, Use Cases & Ecosystem Growth

1. Emerging Trends in Kotlin Multiplatform 1.1 Expansion to New Platforms KMP is branching beyond… Read More

3 weeks ago

Clean Kotlin Multiplatform Code: Best Practices for Maintainable Apps

Why Clean Code Matters in KMP Poorly structured Kotlin Multiplatform projects often face: 80% longer… Read More

4 weeks ago