Android 手机上的“受保护的应用程序”设置
“Protected Apps” setting on Android phones
我们可以要求用户保护我们的应用程序,通过使用(例如华为手机):
Intent intent = new Intent();
intent.setComponent(new ComponentName("com.huawei.systemmanager", "com.huawei.systemmanager.optimize.process.ProtectActivity"));
startActivity(intent);
有没有办法知道应用程序是否受到保护?我试图避免要求用户保护应用程序,例如每次创建应用程序时。
为了其他目的,我可以使用:
List<ResolveInfo> list = context.getPackageManager().queryIntentActivities(
new Intent(Settings.ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS, Uri.parse("package:" + getPackageName()))
,
PackageManager.MATCH_DEFAULT_ONLY);
System.out.println("MY_intent_TEST_1(looks always true): "+( list.size() > 0 ) );
PowerManager pwm = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
System.out.println("MY_intent_TEST_2(true when whitelisted): "+ pwm.isIgnoringBatteryOptimizations(context.getPackageName()) );
P.S。我正在学习:
由于没有暴露相关接口,目前无法得知应用是否被保护。
我们可以要求用户保护我们的应用程序,通过使用(例如华为手机):
Intent intent = new Intent();
intent.setComponent(new ComponentName("com.huawei.systemmanager", "com.huawei.systemmanager.optimize.process.ProtectActivity"));
startActivity(intent);
有没有办法知道应用程序是否受到保护?我试图避免要求用户保护应用程序,例如每次创建应用程序时。
为了其他目的,我可以使用:
List<ResolveInfo> list = context.getPackageManager().queryIntentActivities(
new Intent(Settings.ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS, Uri.parse("package:" + getPackageName()))
,
PackageManager.MATCH_DEFAULT_ONLY);
System.out.println("MY_intent_TEST_1(looks always true): "+( list.size() > 0 ) );
PowerManager pwm = (PowerManager) context.getSystemService(Context.POWER_SERVICE);
System.out.println("MY_intent_TEST_2(true when whitelisted): "+ pwm.isIgnoringBatteryOptimizations(context.getPackageName()) );
P.S。我正在学习:
由于没有暴露相关接口,目前无法得知应用是否被保护。