Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a way to check if "Install from unknown source" is enabled on Android?

Tags:

android

I want to prompt the user if this option is not enabled.

like image 505
Eveets Avatar asked Jul 12 '11 13:07

Eveets


2 Answers

Here is another way to check this setting:

boolean isNonPlayAppAllowed = Settings.Secure.getInt(getContentResolver(), Settings.Secure.INSTALL_NON_MARKET_APPS) == 1;

Also this code to show the setting to user might me useful:

if (!isNonPlayAppAllowed) {
    startActivity(new Intent(android.provider.Settings.ACTION_SECURITY_SETTINGS));
}
like image 137
MSquare Avatar answered Sep 23 '22 16:09

MSquare


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
}
like image 25
Cristian Avatar answered Sep 23 '22 16:09

Cristian