Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Programmatically find whether installing from unknown sources is allowed

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?

like image 459
Mikle Avatar asked Jun 13 '11 16:06

Mikle


People also ask

How do I turn on Allow unknown sources?

Navigate to Settings. Search for and select Install unknown apps. Then, tap Install unknown apps again.


2 Answers

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));
}
like image 58
MSquare Avatar answered Sep 29 '22 09:09

MSquare


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.)

like image 43
Mikle Avatar answered Sep 29 '22 09:09

Mikle