Programmatically find whether installing from unknown sources is allowed

后端 未结 3 1341
慢半拍i
慢半拍i 2020-12-30 04:38

I need to find whether the current Android device allows to install apps from sources other than the market. This option appears in the settings UI under Applications named

3条回答
  •  感动是毒
    2020-12-30 05:13

    Here is the code that uses the mentioned setting:

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

    Also showing the setting to user might me useful:

    if (!isNonPlayAppAllowed) {
        startActivity(new Intent(android.provider.Settings.ACTION_SECURITY_SETTINGS));
    }
    

提交回复
热议问题