由於(與upvotes)@Paradopolis和@Geobits w^ith這個問題和答案組合。 @Geobits給出了正確的答案。我張貼我的,如果有人需要一個詳細的總結和方法來獲取/設置該選項的狀態。
PACKAGE_VERIFIER_ENABLE
首先在API級14與android.provider.Settings.Secure
下"verifier_enable"
值定義。
API級14(4.0.1_r1):
public static final String PACKAGE_VERIFIER_ENABLE = "verifier_enable";
它的值和定義的類API級17其值android.provider.Settings.Global
API級17(4.2_r1)下成爲"package_verifier_enable"
之後改變:
public static final String PACKAGE_VERIFIER_ENABLE = "package_verifier_enable";
PACKAGE_VERIFIER_ENABLE
屬性被定義爲public,但在定義時被註解隱藏。所以我們不能使用它作爲Settings.Secure.PACKAGE_VERIFIER_ENABLE
或Settings.Global.PACKAGE_VERIFIER_ENABLE
,但我們可以使用它的價值。
如果有人需要確定是否包驗證被選中/取消,或選中/取消其程序可以使用下面的類:
public abstract class DeviceSettings {
public enum SettingsCheckStatus {
CHECKED, UNCHECKED, UNDEFINED
}
public static SettingsCheckStatus isVerifyAppsChecked(Context context) {
// PACKAGE_VERIFIER_ENABLE is added after API level 14.
// Its value changed at API level 17
int packageVerifierEnabledAsInt = -1;
if (Build.VERSION.SDK_INT >= 17) {
packageVerifierEnabledAsInt = Settings.Global.getInt(context.getContentResolver(), "package_verifier_enable", -1);
} else if (Build.VERSION.SDK_INT >= 14) {
packageVerifierEnabledAsInt = Settings.Secure.getInt(context.getContentResolver(), "verifier_enable", -1);
} else {
// No package verification option before API Level 14
}
SettingsCheckStatus settingsCheckStatus = SettingsCheckStatus.UNDEFINED;
switch (packageVerifierEnabledAsInt) {
case 0:
settingsCheckStatus = SettingsCheckStatus.UNCHECKED;
break;
case 1:
settingsCheckStatus = SettingsCheckStatus.CHECKED;
break;
default:
break;
}
return settingsCheckStatus;
}
/**
*
* @param context
* @param checked
* @return
*
* You must add <b>android.permission.WRITE_SECURE_SETTINGS</b> to your application's manifest file to use this method.
* Keep in mind, lint error checking may show an error on your manifest. <a href="http://stackoverflow.com/questions/13801984/permission-is-only-granted-to-system-app">See link to solve it.</a> <br>
* Note that, this method <b>can only work on rooted devices or if your application is going to be a system app.<b>
*
*/
public static boolean setVerifyAppsChecked(Context context, boolean checked) {
boolean operationCompletedSuccessfully = false;
int packageVerifierEnabledAsInt = checked ? 1 : 0;
try {
if (Build.VERSION.SDK_INT >= 17) {
operationCompletedSuccessfully = Settings.Global.putInt(context.getContentResolver(), "package_verifier_enable", packageVerifierEnabledAsInt);
} else if (Build.VERSION.SDK_INT >= 14) {
operationCompletedSuccessfully = Settings.Secure.putInt(context.getContentResolver(), "verifier_enable", packageVerifierEnabledAsInt);
} else {
// No package verification option before API Level 14
}
} catch (Throwable t) {
// Your device is not rooted or your app is not a system app.
}
return operationCompletedSuccessfully;
}
}
你猜對了。我只是看着源頭,就是這樣。它被列爲HIDE,所以你不能訪問它,但是如果你可以從構建中獲得框架jar的副本,你可以訪問所有隱藏的東西。 –