0

I have an activity in one application with the following intent filter:

<intent-filter>
    <data
        android:scheme="http" android:host="test.co.uk"/>
    <action android:name="android.intent.action.VIEW"/>
    <category android:name="android.intent.category.DEFAULT"/>
    <category android:name="android.intent.category.BROWSABLE" />
</intent-filter>

From a separate application, I am firing an intent with a URI prefixed with http:

Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse("http://test.co.uk"));
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);

When this intent is triggered, the expected Android behaviour occurs - the OS asks me if I would like to open a web browser, or my own app (since they are both registered to receive http data).

Question

My aim is to prioritize one of these apps over the other programmatically - I would like to use my own application if it is installed, and if not, fall back to opening the link in a browser. Is this possible without causing the OS to ask the user which application they would like to use?

Attempted

I have the following code that queries the package manager to find all activities that can handle my intent. See below:

PackageManager pm = getPackageManager();
List<ResolveInfo> resolveInfoList = pm.queryIntentActivities(intent, 0);

I am trying to use the ResolveInfo object for each activity returned (in this case there are 2 activities). What I have attempted is to get the host from each ResolveInfo so I can determine which one is specifically listening for test.co.uk (so I can directly fire an intent pointing to the package of this application) but I cannot see any way of retrieving the host.

Mike Baxter
  • 6,868
  • 17
  • 67
  • 115

1 Answers1

0

You can check if your app is installed like here Check if application is installed - Android , and then launch an explicit intent for that app if it is installed.

Community
  • 1
  • 1
isma3l
  • 3,833
  • 1
  • 22
  • 28