开发者

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

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜