Programmatically find whether installing from unknown sources is allowed

只谈情不闲聊 提交于 2019-12-18 12:22:21

问题


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 "Unknown sources".

The setting basically allows you to download and install APKs that did not originate from the Google app market.

How do I check whether this flag is on or off using code?


回答1:


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



回答2:


This setting is called "INSTALL_NON_MARKET_APP" (click for documentation).

(I basically already typed the question when I found the answer hidden deep within documentation, with a different name, so I decided to post the question and self answer, since it's not trivial.)



来源:https://stackoverflow.com/questions/6333602/programmatically-find-whether-installing-from-unknown-sources-is-allowed

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!