Skip to content

BrowserAwitch into App #62

@skauss

Description

@skauss

Hi
we use

  • drop-in:6.7.0
  • which depends on browser-switch:2.3.2
  • Any Android version
  • Any device

we use browser-switch in an special PayPalPlus flow.
Our App has an Intent filter to open in case an URL is for our web side.
We do this for the "Google Search Api" to link into our app or for generic mailing to our customer (Web and App customer)
In case the App is installed the app is opens, if not the browser is opens.

Now the problem :
The payment browser switch url got to our Web side (JavaScript Payment side) but also the app is registered to the url.
Example https://www.domain.com/payment/obj/angular-apps/standalone/paypal-plus-installments/?s......

AndroidManifest.xml

         <intent-filter android:autoVerify="true">
                <action android:name="android.intent.action.VIEW" />
                <category android:name="android.intent.category.DEFAULT" />
                <category android:name="android.intent.category.BROWSABLE" />
                <data
                    android:host="www.domain.com"
                    android:scheme="https" >
                </data>
            </intent-filter>

In case of an browser switch the app is opened because BrowserSwitchClient.start()
Didn't check for the possibility the App is also registered to the browserSwitchUrl.

customTabsInternalClient.launchUrl(activity, browserSwitchUrl, launchAsNewTask);

class ChromeCustomTabsInternalClient {
....
    void launchUrl(Context context, Uri url, boolean launchAsNewTask) {
        CustomTabsIntent customTabsIntent = customTabsIntentBuilder.build();
        if (launchAsNewTask) {
            customTabsIntent.intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        }
        customTabsIntent.launchUrl(context, url);
    }
}

Here is no customTabsIntent.setPackage("browser.package we found");

An solution cut be to check if the App is registered for the browserSwitchUrl
And if so set the customTabsIntent.intent.setPackage("Browser we found");
before customTabsIntent.launchUrl(context, url);

    private void checkAppPackageForActionView(Activity activity, Intent launchUrlInBrowser, String urlToLoad) {
        String applicationPackageName = activity.getPackageName();

        PackageManager pm = activity.getPackageManager();
        Intent activityIntent = new Intent().setAction(Intent.ACTION_VIEW)
                .setData(Uri.parse(urlToLoad));

        List<ResolveInfo> resolvedActivityList = pm.queryIntentActivities(activityIntent, 0);
        boolean packageView = false;

        ArrayList<ResolveInfo> packagesSupportingCustomTabs = new ArrayList<>();
        for (ResolveInfo info : resolvedActivityList) {
            Intent serviceIntent = new Intent();
            serviceIntent.setAction(ACTION_CUSTOM_TABS_CONNECTION);
            serviceIntent.setPackage(info.activityInfo.packageName);

            // check if application package also handle the url
            if (applicationPackageName == null || info.activityInfo.packageName.equals(applicationPackageName)) {
                packageView = true;
            } else {
                packagesSupportingCustomTabs.add(info);
            }
        }
        if (packagesSupportingCustomTabs.size() > 0 && packageView) {
            ResolveInfo info = packagesSupportingCustomTabs.get(0);
            if (info != null && info.activityInfo != null ) {
                launchUrlInBrowser.setPackage(info.activityInfo.packageName);
            }
        }
    }

This check must be for installed ChromeCustomTab and for the activity.startActivity part in the BrowserSwitchClient

Regards

Stephan

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions