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

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

  • 什么是android UI线程堆栈大小限制以及如何克服它?
  • 如何在android http POST中添加参数?
  • Android Studio显示对话框“无法创建调试桥:无法启动adb服务器:无法获取'adb版''的结果
  • LiveData与Handler和LocalBroadcast
  • 获取Android设备的唯一ID?
  • Android中MediaPlayer的速度控制
  • Android应用程序在addAccountExplicitly(帐户,密码,null)崩溃;
  • Android:当您的应用在后台运行时,在通知上使用AUTO-CANCEL
  • 以下是检查此设置的另一种方法:

    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 }