Question

Is there a way for my Android app to detect whether side loading is enabled on the user's phone? The user has already installed my app on their phone. Now I'd like to programmatically test whether the user has sideloading has enabled, i.e., whether the user has changed their settings to allow installing apps from off-market sources. If there an API to get this information? Is there a setting stored somewhere that I can programmatically query (without requiring user interaction)?

Was it helpful?

Solution

@TargetApi(Build.VERSION_CODES.JELLY_BEAN_MR1)
@SuppressWarnings("deprecation")
public static boolean isSideloadingEnabled(Context ctx) {
    final ContentResolver cr = ctx.getContentResolver();

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN_MR1) {
        //Pull from Secure settings for (API < 17)
        return Settings.Secure.getInt(cr, Settings.Secure.INSTALL_NON_MARKET_APPS, 0) == 1;
    } else {
        //Setting was moved to Global settings in (API >= 17)
        return Settings.Global.getInt(cr, Settings.Global.INSTALL_NON_MARKET_APPS, 0) == 1;
    }
}

Javadoc for the INSTALL_NON_MARKET_APPS states:

Whether the package installer should allow installation of apps downloaded from sources other than Google Play. 1 = allow installing from other sources 0 = only allow installing from Google Play

OTHER TIPS

Apparently this is provided by the INSTALL_NON_MARKET_APP setting. See the link for how to query this on the latest versions of Android.

For a backward-compatible way to query this that also works with older versions of Android, see https://stackoverflow.com/a/17777053/781723.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top