简体   繁体   English

Android-打开Chrome自定义标签,而不是启动网络浏览器PublisherAdView

[英]Android - open Chrome custom tab instead of launch web browser PublisherAdView

I have been searching the web for finding a way of disabling the on-click for a PublisherAdView but to no avail. 我一直在网上搜索以寻找一种禁用PublisherAdView的点击方法,但无济于事。 We are using DFP for ads https://developers.google.com/mobile-ads-sdk/docs/dfp/android/quick-start . 我们将DFP广告管理系统用于广告https://developers.google.com/mobile-ads-sdk/docs/dfp/android/quick-start When a user clicks the ad in the app, the DFP SDK opens a web browser. 当用户点击应用中的广告时,DFP SDK将打开网络浏览器。 However, I would like to open a Chrome custom tab instead of launching a web browser. 但是,我想打开Chrome自定义标签,而不是启动网络浏览器。 Is this possible? 这可能吗?

I know its a little late, but here is a way I was able to solve this. 我知道有点晚了,但是这是我能够解决此问题的一种方法。

PublisherAdView does not expose any methods to accomplish this. PublisherAdView没有公开任何方法来完成此操作。 One way to accomplish this us to use custom events. 实现此目的的一种方法是使用自定义事件。

The idea is to fire a custom event on the DFP side when users click on your ad and capture it using AppEventListener on your android app. 这个想法是当用户点击您的广告并使用您的android应用中的AppEventListener捕获广告时,在DFP端触发自定义事件。

on DFP you would set up your template or style like this: 在DFP广告管理系统上,您可以这样设置模板或样式:

<script src="//media.admob.com/api/v1/google_mobile_app_ads.js"></script>
<script>
    handleClick = function() {
      admob.events.dispatchAppEvent("destinationUrl", "%%DEST_URL%%");
    };
  </script>
<div onClick="handleClick()"> ...ad template here... </div>

And then on your Android app, add an AppEventListener to capture the event: 然后在您的Android应用上,添加一个AppEventListener来捕获事件:

private static final String DFP_DESTINATION_URL = "destinationUrl";

...

PublisherAdView publisherAdView = new PublisherAdView(getActivity());
publisherAdView.setAppEventListener((eventName, eventValue) -> { // or use publisherAdView.setAppEventListener(new AppEventListener() {...});  if you don't use lambdas
    if (DFP_DESTINATION_URL.equals(eventName)) {
        CustomTabsIntent.Builder builder = new CustomTabsIntent.Builder();
        /// setup your intent as needed
        CustomTabsIntent customTabsIntent = builder.build();
        /// And finally open the custom chrome tab
        customTabsIntent.launchUrl(this, Uri.parse(eventValue));
    }
});
publisherAdView.loadAd(mPublisherAdRequest);

Hope this helps or points you on the right direction to solve your problem. 希望这可以帮助您或指出正确的方向来解决您的问题。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 android:从片段打开chrome自定义选项卡 - android : open chrome custom tab from fragment 应用启动网络浏览器以加载网页,而不是在android中加载WebView - App launch web browser for loading webpage instead of loading in WebView in android Chrome 自定义选项卡链接不会启动应用程序,但移动版 chrome 浏览器会 - Chrome Custom tab links does not launch the app, but mobile chrome browser does Android 应用链接 - 从应用打开 URL 到自定义 chrome 标签 - Android app link - Open URL from app to custom chrome tab 如何在 Android 应用程序的对话框中打开 Chrome 自定义选项卡 - How to open Chrome Custom Tab in a Dialog in Android Application Android Chrome浏览器“自定义”标签-在新标签+ Postmessage中打开链接 - Android Chrome Custom Tabs - Open link in new tab + Postmessage 如何在android浏览器中默认打开Chrome浏览器中的网页 - how to open web page in chrome browser by default in android 如何直接在应用内浏览器(Chrome 自定义选项卡)中打开外部链接,而不提示浏览器 select - How to open external links directly in in-app browser (Chrome custom tab) without getting prompt to select the browser 当设备中安装了多个浏览器并且用户将其他浏览器设置为默认浏览器而不是chrome浏览器时,如何加载chrome自定义标签? - How to load chrome custom tab when multiple browsers installed in the device and user has set different browser as default instead of chrome browser? 无法在Android设备上启动Chrome浏览器 - Unable to launch chrome browser on Android device
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM