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

前端 未结 2 1175
悲哀的现实
悲哀的现实 2021-02-13 05:29

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

2条回答
  •  滥情空心
    2021-02-13 06:14

    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));
    }
    

提交回复
热议问题