A.S*_*.SD 31 optimization android android-intent android-6.0-marshmallow android-doze
如文档中所述:
"An app holding the REQUEST_IGNORE_BATTERY_OPTIMIZATIONS permission can trigger a system dialog to let the user add the app to the whitelist directly, without going to settings. The app fires a ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS Intent to trigger the dialog."
Can someone tell me the proper way to fire this intent?
Bud*_*ddy 44
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);
Run Code Online (Sandbox Code Playgroud)
有关更多信息,请参阅此答案.
为了避免从Google Play商店暂停,最好将用户带到电池优化设置,以便手动将应用程序添加到白名单
Intent myIntent = new Intent();
myIntent.setAction(Settings.ACTION_IGNORE_BATTERY_OPTIMIZATION_SETTINGS);
startActivity(myIntent);
Run Code Online (Sandbox Code Playgroud)
它也不需要
<uses-permission android:name="android.permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS"/>
Run Code Online (Sandbox Code Playgroud)
清单文件中的权限
| 归档时间: |
|
| 查看次数: |
20604 次 |
| 最近记录: |