吐槽:vivo的电池优化是不能手动打开的,只能用代码调用,而且跟小米手机的代码不一样
vivo忽略电池优化代码:
Intent intent = new Intent(Intent.ACTION_MAIN);
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.addCategory(Intent.CATEGORY_LAUNCHER);
ComponentName cn = ComponentName.unflattenFromString("com.android.settings/.Settings$HighPowerApplicationsActivity");
intent.setComponent(cn);
startActivity(intent);
小米手机忽略电池优化代码:(在vivo上无效)
Intent intent = new Intent(Settings.ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS);
intent.setData(Uri.parse("package:"+this.getPackageName()));
startActivity(intent);
记得加上权限
<uses-permission android:name="android.permission.REQUEST_IGNORE_BATTERY_OPTIMIZATIONS"/>