Android(Kotlin)

Android REQUEST_IGNORE_BATTERY_OPTIMIZATIONS

----___<<<<< 2022. 4. 29. 09:29

 

<uses-permission android:name="android.permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS" />
class MainActivity : AppCompatActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)

        val pm = getSystemService(Context.POWER_SERVICE) as PowerManager
        val packageName = packageName
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.M) {
            if (pm.isIgnoringBatteryOptimizations(packageName)) {

            } else {    // 메모리 최적화가 되어 있다면, 풀기 위해 설정 화면 띄움.
                val intent = Intent()
                intent.action = Settings.ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS
                intent.data = Uri.parse("package:$packageName")
                startActivityForResult(intent, 0)
            }
        }


    }
}

'Android(Kotlin)' 카테고리의 다른 글

android 12 splash  (0) 2022.05.15
SaveFile Android kotlin  (0) 2022.05.02
기존 Retrofit Callback 계속 붙이면?  (0) 2022.04.13
Android PeriodicWorkRequest Memo  (0) 2022.04.07
WorkManager Chaining  (0) 2022.03.30