问题
I am using newly launched Chrome Custom tabs for android instead of using webviews. This is the link to their documentation
Here is the code that shows how to use it.
String url = ¨https://paul.kinlan.me/¨;
CustomTabsIntent.Builder builder = new CustomTabsIntent.Builder();
CustomTabsIntent customTabsIntent = builder.build();
customTabsIntent.launchUrl(this, Uri.parse(url));
Question is that I want to add Intent.EXTRA_REFERRER to this. below is the para copied from their blog in their own words..
It's usually very important for websites to track where their traffic is coming from. Make sure you let them know you are sending them users by setting the referrer when launching your Custom Tab
intent.putExtra(Intent.EXTRA_REFERRER,
Uri.parse(Intent.URI_ANDROID_APP_SCHEME + "//" + context.getPackageName()));
I failed to figure out any intent created to launch custom tabs.. Where to add this line?? If somebody has came across this, help please.
回答1:
you can put the extra on the Intent that is inside the CustomTabsIntent created by the builder like the following:
String url = ¨https://paul.kinlan.me/¨;
CustomTabsIntent.Builder builder = new CustomTabsIntent.Builder();
CustomTabsIntent customTabsIntent = builder.build();
customTabsIntent.intent.putExtra(Intent.EXTRA_REFERRER,
Uri.parse("android-app://" + context.getPackageName()));
customTabsIntent.launchUrl(this, Uri.parse(url));
Explanation: Under the hood, a Custom tab is opened by using regular a Intent with a set of Extras that configure the UI customization. It's possible to see more on how it works at the Low Level API section of the docs. When CustomTabsIntent.Builder#build()
is called, it creates a CustomTabsIntent, with a properly configured Intent inside it. This intent is still exposed by the API and that's what we use to add the EXTRA_REFERRER.
来源:https://stackoverflow.com/questions/37937244/how-to-add-extra-referrer-to-customtabsintent-builder-in-chrome-custom-tab-for-a