如果未启用此选项,我想提示用户。
答案 0 :(得分:11)
以下是检查此设置的另一种方法:
boolean isNonPlayAppAllowed = Settings.Secure.getInt(getContentResolver(), Settings.Secure.INSTALL_NON_MARKET_APPS) == 1;
此代码向用户显示设置可能对我有用:
if (!isNonPlayAppAllowed) {
startActivity(new Intent(android.provider.Settings.ACTION_SECURITY_SETTINGS));
}
答案 1 :(得分:4)
Uri settingsUri = Settings.Secure.CONTENT_URI;
String[] projection = new String[]{Settings.System.VALUE};
String selection = Settings.Secure.NAME + " = ? AND " +
Settings.Secure.VALUE + " = ?";
String[] selectionArgs = {Settings.Secure.INSTALL_NON_MARKET_APPS,
String.valueOf(1)};
Cursor query = getContentResolver().query(settingsUri, projection,
selection, selectionArgs, null);
if (query.getCount() == 1) {
// it's enabled
} else {
// it's not
}