【发布时间】:2020-11-25 21:58:34
【问题描述】:
我们可以要求用户通过使用(例如华为手机)来保护我们的应用:
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()) );
附:我正在学习:"Protected Apps" setting on Huawei phones, and how to handle it
【问题讨论】:
标签: java android android-intent permissions huawei-mobile-services