2
我只是想在我的應用程序中禁用電池優化。我用下面的代碼片段ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS在未開火
Intent intent = new Intent();
String packageName = context.getPackageName();
PowerManager pm = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
if (pm.isIgnoringBatteryOptimizations(packageName))
intent.setAction(Settings.ACTION_IGNORE_BATTERY_OPTIMIZATION_SETTINGS);
else {
intent.setAction(Settings.ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS);
intent.setData(Uri.parse("package:" + packageName));
}
context.startActivity(intent);
的片段被解僱,但沒有表現出任何選項來禁用電池優化。而不會在日誌中顯示任何錯誤。請幫助
定義你有你'AndroidManifest.xml'的'REQUEST_IGNORE_BATTERY_OPTIMIZATIONS'許可
REQUEST_IGNORE_BATTERY_OPTIMIZATIONS
許可? –謝謝你,夥計你救了我的一天 –