5
我有一個應用程序,可在某些活動關閉時顯示插頁式廣告。我使用其他活動來顯示廣告。到目前爲止,它顯示廣告正確,但沒有任何反應,當我點擊廣告。我已經在很多設備上測試過它,測試版測試人員報告了相同的行爲。日誌中沒有錯誤。如果我使用調試版本或已上傳到Play商店的已簽名APK(如果它很重要,它在alpha狀態下發布),情況也是如此。我使用最新的Play Store Services SDK。顯示AdMob插頁式廣告,但無法點擊它
這可能是什麼原因?
我的活動,顯示廣告(我用的是正確的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>
我希望你能提供任何幫助。
UPDATE
看來,我設法找到問題。據相關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" />
很抱歉的混亂,我不能當我這樣做的改變召回。
難道這就是你所做的唯一的變化?我有「好版本」,但仍無法點擊廣告。 –
是的,是的。你有沒有在另一個測試設備上嘗試過它? – drk
我已經找到解決我的問題了。我在調用finish()函數後顯示插頁式廣告。應用程序顯示廣告,因爲它之前被加載,但應用程序已經消失,所以點擊沒有奏效。 –