Android Question [SOLVED] How to determine default browser on device - WITHOUT using android.permission.QUERY_ALL_PACKAGES

JackKirk

Well-Known Member
Licensed User
Longtime User
I recently worked out how to use Erel's 2011 code:

https://www.b4x.com/android/forum/t...-a-particular-type-of-intent.13580/post-76825

to determine the default browser in use on an Android device - see:

https://www.b4x.com/android/forum/threads/solved-how-to-determine-default-browser-on-device.162506/

Unfortunately this seemed to require android.permission.QUERY_ALL_PACKAGES in the B4A project manifest.

This is now heavily frowned upon by Google:

https://support.google.com/googleplay/android-developer/answer/10158779

which probably means for most practical purposes you are not going to get the B4A app published.

I looked all over for a solution to this and eventually found it by asking Windows Copilot - of which I am becoming a huge fan.

I asked it:
how do i use android manifest <queries> to enable querying of all possible browsers
(I had already worked out that <queries> may be the answer).

It responded with (copy paste does not do it's response layout justice):
To enable querying of all possible browsers in your Android app, you can use the <queries> element in your AndroidManifest.xml file. This element allows your app to specify the set of other apps it intends to interact with, which is necessary for package visibility starting from Android 11 (API level 30).

Here’s an example of how you can configure the <queries> element to query for browsers:

XML

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.myapp">

<queries>
<!-- Query for all browsers -->
<intent>
<action android:name="android.intent.action.VIEW" />
<data android:scheme="http" />
</intent>
<intent>
<action android:name="android.intent.action.VIEW" />
<data android:scheme="https" />
</intent>
</queries>

<!-- Other manifest entries -->
</manifest>

AI-generated code. Review and use carefully. More info on FAQ.
In this example:

  • The <queries> element contains two <intent> elements.
  • Each <intent> element specifies an action (android.intent.action.VIEW) and a data scheme (http and https), which are common schemes handled by browsers.
This configuration ensures that your app can query for any installed browser that can handle HTTP and HTTPS URLs12.

If you have any more questions or need further assistance, feel free to ask!
Which is encouraging but I need it in B4A Manifest form so I then asked it:
how would i add this to a b4a manifest
It responded with:
To add the <queries> element to your B4A (Basic4Android) manifest, you can use the AddManifestText method. Here’s how you can do it:

  1. Open your B4A project.
  2. Go to the Manifest Editor.
  3. Add the following code to include the <queries> element:
AddManifestText(<queries>
<intent>
<action android:name="android.intent.action.VIEW" />
<data android:scheme="http" />
</intent>
<intent>
<action android:name="android.intent.action.VIEW" />
<data android:scheme="https" />
</intent>
</queries>)

This code snippet ensures that your app can query for all browsers that handle HTTP and HTTPS URLs1.

If you encounter any issues or need further assistance, feel free to ask!
So I added:
B4X:
AddManifestText(
<queries>
    <intent>
        <action android:name="android.intent.action.VIEW" />
        <data android:scheme="http" />
    </intent>
    <intent>
        <action android:name="android.intent.action.VIEW" />
        <data android:scheme="https" />
    </intent>
</queries>)
to my B4A project manifest and removed the android.permission.QUERY_ALL_PACKAGES - and it all works!!!!!
 
Top