问题描述
我有一个应用程序,当某些活动被关闭显示的页内广告。我用一个不同的活动,以显示广告。到目前为止,它显示了广告正常,但没有任何反应,当我点击广告。我已经在许多设备上进行了测试和Beta测试者报告相同的行为。有日志中没有错误。这是相同的,如果我使用调试版本或签名的APK被上传到Play商店(它发表在α波状态,如果它事项)。我用的是最新的Play商店服务SDK。
I've got an app that displays an Interstitial Ad when certain activity is closed. I use a different activity to show the Ad. So far it shows the Ad correctly but nothing happens when I click on the Ad. I've tested it on many devices and beta testers report the same behavior. There are no errors in the logs. It's the same if I use debug build or signed APK that is uploaded to the play store (it's published in alpha state if it matters). I use the latest Play Store Services SDK.
可能是什么原因?
我的活动,显示广告(我用实际code正确的设备ID)
My activity that shows the Ad (I use the correct unit id in the actual code)
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;
}
}
布局(我试着不要同时使用相同的结果任何布局)。
The layout (I've tried to not use any layouts with same results).
<?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>
我会AP preciate任何帮助,您可以提供。
I would appreciate any help you can provide.
更新
看来我设法找到问题。它涉及到AndroidManifest配置:旧的,广告是不可点击的:
It seems that I managed to find the problem. It was related to the AndroidManifest configuration:Old one, Ads are not clickable:
<activity
android:name="com.google.android.gms.ads.AdActivity"
android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"
android:launchMode="singleInstance" />
好的,正常工作
Good one, works fine:
<activity
android:name="com.google.android.gms.ads.AdActivity"
android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize" />
很抱歉的混乱,我不能当我做了这种改变还记得。
Sorry for the confusion, I cant recall when I did that change.
推荐答案
它的工作肯定
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();
}
}
这篇关于AdMob的插页式广告的显示,但不能点击它的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!