android - AdMob 插页式广告已显示但无法点击

标签 android admob

我有一个应用程序可以在某些 Activity 关闭时显示插页式广告。我使用不同的 Activity 来展示广告。到目前为止,它正确显示了广告,但当我点击广告时没有任何反应。我已经在许多设备上测试过它,并且 Beta 测试人员报告了相同的行为。日志中没有错误。如果我使用上传到 Play 商店的调试版本或签名 APK,情况是一样的(如果重要的话,它会以 alpha 状态发布)。我使用最新的 Play Store Services SDK。

这可能是什么原因?

我展示广告的 Activity (我在实际代码中使用了正确的单元 ID)

import android.app.Activity;
import android.content.Context;
import android.location.Location;
import android.location.LocationManager;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.ProgressBar;

import com.google.android.gms.ads.AdListener;
import com.google.android.gms.ads.AdRequest;
import com.google.android.gms.ads.InterstitialAd;

public class AdFullScreen extends Activity {

    private static final String TAG = "AdFullScreen";
    private static final String AD_UNIT_ID = "my-unit-id";

    private InterstitialAd interstitialAd;
    ProgressBar prgrssBrAd;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);

        setContentView(R.layout.ad_layout);

        prgrssBrAd = (ProgressBar) findViewById(R.id.prgrssBrAd);

        interstitialAd = new InterstitialAd(this);
        interstitialAd.setAdUnitId(AD_UNIT_ID);

        interstitialAd.setAdListener(new AdListener() {
            @Override
            public void onAdLoaded() {
                Log.e(TAG, "onAdLoaded");
                prgrssBrAd.setVisibility(View.GONE);
                if (interstitialAd.isLoaded()) {
                    interstitialAd.show();
                } else {
                    Log.e(TAG, "Interstitial ad was not ready to be shown.");
                    finish();
                    return;
                }
            }

            @Override
            public void onAdFailedToLoad(int errorCode) {
                String message = String.format("onAdFailedToLoad (%s)",
                        getErrorReason(errorCode));
                Log.e(TAG, message);
                finish();
                return;
            }

            @Override
            public void onAdClosed() {
                finish();
                return;
            }

            @Override
            public void onAdLeftApplication() {
                Log.e(TAG, "onAdLeftApplication");
                finish();
                return;
            }

        });

        LocationManager locationManager = (LocationManager) this
                .getSystemService(Context.LOCATION_SERVICE);
        String locationProvider = LocationManager.GPS_PROVIDER;
        Location lastKnownLocation = locationManager
                .getLastKnownLocation(locationProvider);
        if (lastKnownLocation == null) {
            locationProvider = LocationManager.NETWORK_PROVIDER;
            lastKnownLocation = locationManager
                    .getLastKnownLocation(locationProvider);
            Log.e(TAG, "Last location not available by GPS");
        } else {
            Log.e(TAG, "Last location available by GPS");
        }

        // Check the logcat output for your hashed device ID to get test ads on
        // a physical device.
        AdRequest.Builder bldr = new AdRequest.Builder();

        if (lastKnownLocation != null) {
            Log.e(TAG, "Last location available");
            bldr.setLocation(lastKnownLocation);
        } else {
            Log.e(TAG, "Last location not available by any provider");
        }
        AdRequest adRequest = bldr.build();
        // Load the interstitial ad.
        interstitialAd.loadAd(adRequest);
    }

    @Override
    public void onStart() {
        super.onStart();
        // The rest of your onStart() code.
    }

    @Override
    public void onStop() {
        super.onStop();
        // The rest of your onStop() code.
    }

    /** Gets a string error reason from an error code. */
    private String getErrorReason(int errorCode) {
        String errorReason = "";
        switch (errorCode) {
        case AdRequest.ERROR_CODE_INTERNAL_ERROR:
            errorReason = "Internal error";
            break;
        case AdRequest.ERROR_CODE_INVALID_REQUEST:
            errorReason = "Invalid request";
            break;
        case AdRequest.ERROR_CODE_NETWORK_ERROR:
            errorReason = "Network Error";
            break;
        case AdRequest.ERROR_CODE_NO_FILL:
            errorReason = "No fill";
            break;
        }
        return errorReason;
    }
}

布局(我尝试不使用任何具有相同结果的布局)。

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

    <ProgressBar
        android:id="@+id/prgrssBrAd"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerInParent="true" />

</RelativeLayout>

如果您能提供任何帮助,我将不胜感激。

更新

看来我设法找到了问题所在。它与 AndroidManifest 配置有关: 旧的,广告不可点击:

<activity
    android:name="com.google.android.gms.ads.AdActivity"
    android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"
    android:launchMode="singleInstance" />

很好,工作正常:

<activity
    android:name="com.google.android.gms.ads.AdActivity"
    android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize" />

抱歉造成混淆,我不记得我是什么时候做那个更改的。

最佳答案

一定会成功的

public class AdFullScreen extends Activity implements AdListener {      


private InterstitialAd interstitial;
private String MY_INTERSTITIAL_UNIT_ID = "your unit id here";

@Override
  protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);

    setContentView(R.layout.ad_layout);

 interstitial = new InterstitialAd(this, MY_INTERSTITIAL_UNIT_ID);
    // Create ad request
    AdRequest adRequest = new AdRequest();
    // Begin loading your interstitial
    interstitial.loadAd(adRequest);
    // Set Ad Listener to use the callbacks below
    interstitial.setAdListener((AdListener) this);

@Override
public void onDismissScreen(Ad arg0) {
    // TODO Auto-generated method stub

}

@Override
public void onFailedToReceiveAd(Ad arg0, ErrorCode arg1) {
    // TODO Auto-generated method stub

}

@Override
public void onLeaveApplication(Ad arg0) {
    // TODO Auto-generated method stub

}

@Override
public void onPresentScreen(Ad arg0) {
    // TODO Auto-generated method stub

}

@Override
public void onReceiveAd(Ad add) {
    // TODO Auto-generated method stub
    if (add == interstitial) {

        interstitial.show();
    }
}

关于android - AdMob 插页式广告已显示但无法点击,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23847178/

相关文章:

java - Android 中的原生广告 Admob 到自定义列表适配器

android - 将多个移动广告网络与 Admob Mediation 集成

ionic-framework - 我可以在 CapacitorJS 应用程序中使用 AdSense 在所有 3 个平台 : Web, iOS 和 Android 上展示广告吗?

android - TopAppBar 无法在 Compose 中自动调整高度,TabRow 无法正常工作

android - 使用带有 Tab 的 Activitygroup 未显示第二个 Activity

android - announceforaccessibility 不起作用

没有 Google Play 的 Android Admo

java - 实现与映射值的比较

java - Android如何像在iOS中一样将异步任务分组在一起

android - 如何将适用于 Android 和 iOS 的相同 Google Analytics 属性链接到 AdMob