简体   繁体   中英

Android WearOS ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS is being ignored

On Android WearOS with SDK 28 I am trying to disable doze mode. From my understanding, the following code will disable doze mode:

PowerManager pm = (PowerManager) getSystemService(Context.POWER_SERVICE);
boolean isIgnoringBatteryOptimizations = pm.isIgnoringBatteryOptimizations(getPackageName());
if(!isIgnoringBatteryOptimizations){
    Intent intent = new Intent();
    intent.setAction(Settings.ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS);
    intent.setData(Uri.parse("package:" + getPackageName()));
    startActivityForResult(intent, 123);
}

In my manifest I have added

<uses-permission android:name="android.permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS" />

Later in my activity I have added the following code to test if battery optimizations have been disabled (what I understand doze mode to be)

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    PowerManager pm = (PowerManager)getSystemService(Context.POWER_SERVICE);
    boolean isIgnoringBatteryOptimizations = pm.isIgnoringBatteryOptimizations(getPackageName());
    if(isIgnoringBatteryOptimizations){
        // Ignoring battery optimization
        Log.e(logTAG, "WORKED");
    }else{
        // Not ignoring battery optimization
        Log.e(logTAG, "NOPE");
    }
}

What I get in the log is "NOPE". Moreover, doze mode is also not being disabled (which is what I would expect with NOPE being printed). Am I doing something wrong or is it not possible to disable doze mode on WearOS?

갤럭시 워치5 에서도 ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS intent action이 무시됩니다

ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS intent action is ignored in Galaxy Watch 5

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM