Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

BrowserAwitch into App #62

Open
skauss opened this issue Jan 26, 2023 · 2 comments
Open

BrowserAwitch into App #62

skauss opened this issue Jan 26, 2023 · 2 comments

Comments

@skauss
Copy link

skauss commented Jan 26, 2023

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

@sshropshire
Copy link
Contributor

Hi @skauss Browser Switch doesn't offer explicit support for App Links at the moment. I'm not sure if there's a way to do this with any Android APIs. There are some tool to verify app links, but these are available only through the adb shell tool.

@skauss
Copy link
Author

skauss commented Jan 27, 2023

Hi @sshropshire ,

I also think there is no Android API to handle App Links.
But take a closer look into the my code snippet above checkAppPackageForActionView
In there I check if the App is responsible for the urlToLoad.

If so it add in to the Intent launchUrlInBrowser an browser package name which handle the request. launchUrlInBrowser.setPackage(info.activityInfo.packageName);

Now the app didn't start again !

I try to use the same variable names you use in the BrowserSwitch code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants