31

Android R Preview 1 introduced a new permission called QUERY_ALL_PACKAGES. The documentation for the permission says the following:

Allows query of any normal app on the device, regardless of manifest declarations.

Has anyone worked out what this actually does?

I've tried running the following on the emulator image, and the permission had no effect on either of them:

  • packageManager.queryIntentActivities(intent, 0)
  • packageManager.getInstalledPackages(0)
2
  • can you please elabroate wheere you have put this Query and this of ACTION_CAPTURE, DO you have idea for SENDTO, SEND TO MULTIPLE? Jan 12, 2021 at 5:47
  • Yes, it really does not work, I'm also having problems with that.
    – AllanRibas
    May 25, 2022 at 5:44

4 Answers 4

29

Even when permission QUERY_ALL_PACKAGES is added, you still need to add <queries> filter to your AndroidManifest.

E.g. for the launcher app it might be:

<permission android:name="android.permission.QUERY_ALL_PACKAGES" />

<queries>
    <intent>
        <action android:name="android.intent.action.MAIN" />
    </intent>
</queries>
7
  • 1
    Docs about intent filters developer.android.com/training/basics/intents/…
    – Flovettee
    Mar 8, 2021 at 7:58
  • Thanks, this is easier to follow than the accepted answer. If you add more detail about what the permission does and what you need to put in the <queries> element, then I'll make this the accepted answer.
    – Sam
    Mar 8, 2021 at 9:28
  • We only need to query the packageName of the calling component through the Android PackageManager and not access the app itself. So for this also do we have to add the queries in the manifest? Thanks in advance. Apr 26, 2021 at 10:52
  • 8
    I think you should be using <uses-permission> instead of <permission> the way google uses android.googlesource.com/platform/packages/apps/Bluetooth/+/… <permission> means you are declaring / overriding a new permisison and may cause an installation error with DUPLCAITE_PERMISSION on devices lower than Android11 if other apps put this same permssion. <uses-permission> implies you are using a predefined system permission Oct 28, 2021 at 6:31
  • 3
    you should use <uses-permission android:name="android.permission.QUERY_ALL_PACKAGES" /> instead of <permission android:name="android.permission.QUERY_ALL_PACKAGES" />, which means you are requesting that permission while the latter means you are defining the permission (as of android S, this permission is not discouraged)
    – Minami
    Apr 15, 2022 at 10:21
10

They cover this more now that DP2 is out.

Quoting myself:

While I haven't tested this aspect of R DP2 yet, it appears that your app now can't find out what other apps are installed, on a general basis. The cited example is queryIntentActivities(), but to make this really work you would need to seriously lobotomize PackageManager. You can whitelist certain packages and certain <intent-filter> structures to try to get by this for certain use cases. And, this is where the mysterious QUERY_ALL_PACKAGES permission seen in DP1 comes into play — this permission removes these new restrictions. Given the "look for Google Play to provide guidelines for apps that need this permission" caveat, it is safest to assume that if you try using it, eventually you will be banned from the Play Store by a bot.

So, you might want to re-try your experiments on DP2. I plan to do the same in the coming weeks.

17
  • 1
    Thanks! I've accepted this answer since it links to the official documentation, which had enough info for me to get it working. After updating to DP2, my calls to queryIntentActivities() only returned a few apps. I added the <queries> element to the manifest to declare the intents that I was passing to queryIntentActivities(), and then queryIntentActivities() started returning all the relevant apps again.
    – Sam
    Mar 21, 2020 at 0:16
  • 2
    I'm curious about something. On applications that require all apps listing (such as a home launcher app, or a utility app that does stuff to other apps depending on user's input) is adding the permission considered dangerous? Or, does this affect the call PackageManager.getInstalledApplications() ? If it does affect, what should we do to fetch installed applications without adding the permission then? Apr 1, 2020 at 11:47
  • 1
    @FurkanYurdakul: They have language in the docs that suggests that requesting QUERY_ALL_PACKAGES will need to be approved (probably via a form) to be able to distribute your app on the Play Store. Launchers should have few(er) problems, as you can use the <queries> element to whitelist the ability to query for HOME/LAUNCHER activities. I have not done a complete test for what is and is not affected in PackageManager, but my guess is that getInstalledApplications() will be affected. Apr 1, 2020 at 11:59
  • @Sam even I also checked on Android 11 beta, still, all packages list is coming from above APIs. Didn't see any impact as mentioned in the android 11 change doc.
    – Vikram
    Jun 23, 2020 at 10:05
  • 1
    Yes, I had checked with target 30 only. No impact at all.
    – Vikram
    Jun 23, 2020 at 12:38
10

Android 11 introduced changes related to package visibility. These changes affect applications, only if they target Android 11 and above. For more information on these changes, please view the official documentation about package visibility on Android.

https://developer.android.com/training/package-visibility

https://developer.android.com/about/versions/11/privacy/package-visibility

In my case, it was Cordova Android v10.1.1, targetSdkVersion = 30

I added

<queries>
  <package android:name="com.google.android.gm" />
  <package android:name="com.facebook.katana" />
  <intent>
    <action android:name="android.intent.action.VIEW" />
    <data android:scheme="https" />
  </intent>
  <intent>
    <action android:name="android.intent.action.DIAL" />
    <data android:scheme="tel" />
  </intent>
  <intent>
    <action android:name="android.intent.action.SEND" />
    <data android:mimeType="*/*" />
  </intent>
</queries>

to my AndroidManifest.xml

4

If the app tries to communicate to another app then this permission should be added for Android 11+, else those apps won't work/trigger

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.