开发者

Can we turn on or off battery saver mode programmatically using Kotlin in Android?

开发者 https://www.devze.com 2022-12-07 18:37 出处:网络
I want to create an application that will turn on and off power saver mode within itself programmatically with on a button click using android-Kotlin. 

I want to create an application that will turn on and off power saver mode within itself programmatically with on a button click using android-Kotlin. 

I have tried using the intent filter, but it goes to system settings, and then we turn it on or off manua开发者_JAVA百科lly.

code :-

buttonBatterySave.setOnClickListener {
    beep() //sound effect
    val batterySaverIntent = Intent()

    batterySaverIntent.component = ComponentName(
        "com.android.settings",
        "com.android.settings.Settings\$BatterySaverSettingsActivity"
    )
    startActivityForResult(batterySaverIntent, 0)
}

I just want my application to turn on or off by itself within the application with a single button click.

Thank you

0

精彩评论

暂无评论...
验证码 换一张
取 消