如何将 EXTRA_REFERRER 添加到 Chrome 自定义选项卡中的 CustomTabsIntent 构建器 Android
How to add EXTRA_REFERRER to CustomTabsIntent builder in Chrome custom tab for Android
我正在为 android 使用新推出的 Chrome 自定义选项卡,而不是使用网络视图。 This is the link to their documentation
这是显示如何使用它的代码。
String url = ¨https://paul.kinlan.me/¨;
CustomTabsIntent.Builder builder = new CustomTabsIntent.Builder();
CustomTabsIntent customTabsIntent = builder.build();
customTabsIntent.launchUrl(this, Uri.parse(url));
问题是我想添加 Intent.EXTRA_REFERRER。以下是用他们自己的话从他们的博客中复制的段落..
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()));
我没能弄清楚为启动自定义选项卡而创建的任何意图。在哪里添加这一行??如果有人遇到过这个,请帮忙。
您可以将额外内容放在构建器创建的 CustomTabsIntent 中的 Intent 上,如下所示:
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));
说明: 在后台,使用常规 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.
打开自定义选项卡
我正在为 android 使用新推出的 Chrome 自定义选项卡,而不是使用网络视图。 This is the link to their documentation
这是显示如何使用它的代码。
String url = ¨https://paul.kinlan.me/¨;
CustomTabsIntent.Builder builder = new CustomTabsIntent.Builder();
CustomTabsIntent customTabsIntent = builder.build();
customTabsIntent.launchUrl(this, Uri.parse(url));
问题是我想添加 Intent.EXTRA_REFERRER。以下是用他们自己的话从他们的博客中复制的段落..
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()));
我没能弄清楚为启动自定义选项卡而创建的任何意图。在哪里添加这一行??如果有人遇到过这个,请帮忙。
您可以将额外内容放在构建器创建的 CustomTabsIntent 中的 Intent 上,如下所示:
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));
说明: 在后台,使用常规 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.