@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
customTabActivityHelper = new CustomTabActivityHelper();
customTabActivityHelper.setConnectionCallback(this);
}
@Override
protected void onStart() {
super.onStart();
customTabActivityHelper.bindCustomTabsService(this);
}
@Override
public void onCustomTabsConnected() {
Boolean mayLaunchUrlAccepted = customTabActivityHelper.mayLaunchUrl(Uri.parse(“the URL?f=“+params), null, null);
// the mayLaunchUrlAccepted always return true in my case. Even when there is no request sent.
}
customTabsIntent.launchUrl(activity, uri);
CustomTabsIntent customTabsIntent =
new CustomTabsIntent.Builder(customTabActivityHelper.getSession())
.build();
CustomTabActivityHelper.openCustomTab(
this, customTabsIntent, uri, new WebviewFallback());
Hey Yusuf,
Please see my following question below.
——
Chang-Ching Chi
Android Developer | RiskPD RDA
From: Yusuf Ozuysal <yus...@google.com>
Date: Thursday, February 25, 2016 at 10:38 AM
To: Chang Chi <ch...@paypal.com>, "li...@chromium.org" <li...@chromium.org>, "pa...@chromium.org" <pa...@chromium.org>, "yus...@chromium.org" <yus...@chromium.org>, "sbi...@google.com" <sbi...@google.com>, "andr...@google.com" <andr...@google.com>
Cc: "prer...@chromium.org" <prer...@chromium.org>
Subject: Re: How many mayLaunchUrl we can run at a time?
TL;DR MayLaunchUrl calls are not restricted, but throttled. So you can have as many calls as you want as long as you follow up with a corresponding custom tab launch.
There might be a possibility that we want to pre-fetch the content of a certain page right before the user go to next step in our native app, they change the setting or config, we would like to see if that is possible to have it pre-render different pages based on our needs without even open a real tab by calling. Once they open the custom tab then we call a certain api to reset previous unused pre-fetch data in order to save the resource.
customTabsIntent.launchUrl(activity, uri);CustomTabsIntent customTabsIntent =
new CustomTabsIntent.Builder(customTabActivityHelper.getSession())
.build();
CustomTabActivityHelper.openCustomTab(
this, customTabsIntent, uri, new WebviewFallback());
Thanks a lot for reaching out about this!
MayLaunchUrl should only be used after a strong signal from the user that they will go to a certain url and we closely monitor what happened after the mayLaunchUrl call. If an app keeps calling mayLaunchUrl without following up with a corresponding tab launch multiple times, it gets banned from using the API for a while. If this happened on your device, you can reset this by clearing Chrome's data.
Can you please give me more details about the way you say “cleaning Chrome’s data”? Do you mean to say Chrome cache? Is there any API I could use to clean it? Though I think this is not a practical way as it might clean some cookie existed on browser and impact the user experience later on. OR you are referring to a way to clean specific data generated by CustomTabs? (without impacting other chrome data)
Due to technical limitations we can't prerender more than one page currently, so multiple calls to mayLaunchUrl will keep canceling the active one and recreating a new renderer.
I agree with the approach. I think having only one active render and overwriting the old renderers is a good way to go. But if this is really the design, why my mayLaunchUrl still got blocked?
If instead of a strong single with a single url, you have a low confidence signal for a list of urls, you can call mayLaunchUrl with mayLaunchUrl(null, null, bundleList) and give a list of bundles with each bundle containing a single uri with key CustomTabsService#KEY_URL. This version is not throttled that heavily and does also provide DNS prefetching and early preconnect, giving you a boost in load times for all the urls. Even with this, I would avoid using it with 10s of urls since there is a limit on the number of sockets that can be open at a time.
Seems to me, this bundle is looking for a fix set of URL. However, We generate the URL dynamically, I don’t think this approach can provide much helps.When you say sockets, what do you mean specifically in custom tabs? Is there any method you provide can reset the sockets opened by old prerenders?