[英]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.