英文:
Google ad click is not opening the external web browser
问题
我正在尝试在我的应用程序中使用自定义原生广告格式来实现广告 - https://developers.google.com/ad-manager/mobile-ads-sdk/android/native/custom-formats#java_1
所以,根据文档,我正在按照其中描述的方法进行操作并创建广告
...
private void setListeners() {
...
imageView.setOnClickListener(v -> {
nativeCustomFormatAd.performClick("IMAGE");
});
...
}
private NativeCustomFormatAd nativeCustomFormatAd;
AdLoader adLoader = new AdLoader.Builder(context, "/6499/example/native")
.forCustomFormatAd("10063170",
new NativeCustomFormatAd.OnCustomFormatAdLoadedListener() {
@Override
public void onCustomFormatAdLoaded(NativeCustomFormatAd ad) {
// 展示自定义格式并记录印象。
nativeCustomFormatAd = ad;
Drawable drawable = vm.nativeCustomFormatAd.getImage("IMAGE").getDrawable();
imageView.setDrawable(drawable);
}
},
new NativeCustomFormatAd.OnCustomClickListener() {
@Override
public void onCustomClick(NativeCustomFormatAd ad, String s) {
// 处理点击动作
}
})
.withAdListener( ... )
.withNativeAdOptions( ... )
.build();
@SuppressLint("VisibleForTests")
AdManagerAdRequest adManagerAdRequest = new AdManagerAdRequest.Builder().build();
adLoader.loadAd(adManagerAdRequest);
...
所以,看起来很简单,我尝试请求广告,然后在回调中获取NativeCustomFormatAd
,将其保存为类成员,并同时获取drawable
并将其设置到imageView
(以在UI中展示它)。一旦用户点击imageView
,我在点击监听器中收到一个事件并调用nativeCustomFormatAd.performClick("IMAGE")
。
问题是,我期望一旦将广告点击传递给SDK(通过nativeCustomFormatAd.performClick("IMAGE")
),SDK应该打开外部浏览器,但实际上什么都没有发生。
P.S. 我确信nativeCustomFormatAd.performClick("IMAGE")
被调用,而且我也看到SDK获取了点击,因为我在这里收到了回调事件:
...
new NativeCustomFormatAd.OnCustomClickListener() {
@Override
public void onCustomClick(NativeCustomFormatAd ad, String s) {
// 处理点击动作
}
})
...
我在这里漏掉了什么?
英文:
I am trying to implement the ad in my app with Custom Native Ad Format - https://developers.google.com/ad-manager/mobile-ads-sdk/android/native/custom-formats#java_1
So, according to the documentation I am going with the approach described there and creating the ad
...
private void setListeners() {
...
imageView.setOnClickListener(v -> {
nativeCustomFormatAd.performClick("IMAGE");
});
...
}
private NativeCustomFormatAd nativeCustomFormatAd;
AdLoader adLoader = new AdLoader.Builder(context, "/6499/example/native")
.forCustomFormatAd("10063170",
new NativeCustomFormatAd.OnCustomFormatAdLoadedListener() {
@Override
public void onCustomFormatAdLoaded(NativeCustomFormatAd ad) {
// Show the custom format and record an impression.
nativeCustomFormatAd = ad;
Drawable drawable = vm.nativeCustomFormatAd.getImage("IMAGE").getDrawable();
imageView.setDrawable(drawable);
}
},
new NativeCustomFormatAd.OnCustomClickListener() {
@Override
public void onCustomClick(NativeCustomFormatAd ad, String s) {
// Handle the click action
}
})
.withAdListener( ... )
.withNativeAdOptions( ... )
.build();
@SuppressLint("VisibleForTests")
AdManagerAdRequest adManagerAdRequest = new AdManagerAdRequest.Builder().build();
adLoader.loadAd(adManagerAdRequest);
...
So, it looks pretty simple I try to make a request for the ad then I got (in a callback) NativeCustomFormatAd
, save it as a class member, and along with it get drawable
and set it to the imageView
(to present it in the UI). Once a user clicks on the imageView
I get an event in the click listener and invoke nativeCustomFormatAd.performClick("IMAGE");
.
The problem is that I expect that once I transfer the ad click to the SDK (by nativeCustomFormatAd.performClick("IMAGE");) SDK is supposed to open the external browser, but instead nothing happens.
P.S. I am sure that nativeCustomFormatAd.performClick("IMAGE");
getting invoked and also I see that SDK gets the click as I got a callback event here:
...
new NativeCustomFormatAd.OnCustomClickListener() {
@Override
public void onCustomClick(NativeCustomFormatAd ad, String s) {
// Handle the click action
}
})
...
What am I missing here?
答案1
得分: 2
根据您提供的文档链接:
当单击自定义格式广告时,SDK 可能会以以下顺序尝试三种响应方式:
- 如果 AdLoader 提供了 OnCustomClickListener,则调用 OnCustomClickListener。
- 对于广告的每个深链接 URL,尝试查找内容解析器并启动第一个解析的 URL。
- 打开浏览器并导航到广告的传统目标 URL。
此外:
如果您传递了监听对象,则 SDK 会调用其 onCustomClick 方法,然后不再采取其他操作。
因此,似乎您需要传递一个空的 OnCustomClickListener。
英文:
According to the docs you linked:
>When a click is performed on a custom format ad, there are three possible responses from the SDK, attempted in this order:
>
>
>
>1. Invoke the OnCustomClickListener from AdLoader, if one was provided.
>2. For each of the ad's deep link URLs, attempt to locate a content resolver and start the first one that resolves.
>3. Open a browser and navigate to the ad's traditional Destination URL.
Also:
> If you pass a listener object in, the SDK instead invokes its onCustomClick method and takes no further action.
Therefore, it seems you have to pass a null OnCustomClickListener.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论