有没有办法检查Android上是否启用了“从未知来源安装”?

如果未启用此选项,我想提示用户。

以下是检查此设置的另一种方法:

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

此代码向用户显示设置可能对我有用:

 if (!isNonPlayAppAllowed) { startActivity(new Intent(android.provider.Settings.ACTION_SECURITY_SETTINGS)); } 
 Uri settingsUri = Settings.Secure.CONTENT_URI; String[] projection = new String[]{Settings.System.VALUE}; String selection = Settings.Secure.NAME + " = ? AND " + Settings.Secure.VALUE + " = ?"; String[] selectionArgs = {Settings.Secure.INSTALL_NON_MARKET_APPS, String.valueOf(1)}; Cursor query = getContentResolver().query(settingsUri, projection, selection, selectionArgs, null); if (query.getCount() == 1) { // it's enabled } else { // it's not }