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

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

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

2条回答
  •  刺人心
    刺人心 (楼主)
    2021-02-13 05:57

    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
    }
    

提交回复
热议问题