Ho un'app che visualizza un annuncio interstiziale quando viene chiusa un'attività. Uso un'attività diversa per mostrare l'annuncio. Finora mostra correttamente l'annuncio ma non succede nulla quando clicco sull'annuncio. L'ho provato su molti dispositivi e i beta tester riportano lo stesso comportamento. Non ci sono errori nei log. È lo stesso se uso il debug build o l'APK firmato che viene caricato nel Play Store (è pubblicato in stato Alpha se è importante). Uso l'ultimo SDK di Play Store Services.L'annuncio interstitial di AdMob viene mostrato ma non è possibile fare clic su di esso
Quale potrebbe essere la ragione di questo?
mia attività che mostra l'annuncio (io uso l'unità corretta id nel codice vero e proprio)
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;
}
}
Il layout (ho cercato di non utilizzare i layout con gli stessi risultati).
<?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>
Apprezzerei qualsiasi aiuto tu possa fornire.
UPDATE
Sembra che sono riuscito a trovare il problema. E 'stato legato alla configurazione AndroidManifest: Vecchio, Gli annunci non sono cliccabili:
<activity
android:name="com.google.android.gms.ads.AdActivity"
android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize"
android:launchMode="singleInstance" />
buona, funziona bene:
<activity
android:name="com.google.android.gms.ads.AdActivity"
android:configChanges="keyboard|keyboardHidden|orientation|screenLayout|uiMode|screenSize|smallestScreenSize" />
Ci scusiamo per la confusione, non posso ricordare quando ho fatto che il cambiamento .
Era questo l'unico cambiamento che avete fatto? Ho la "buona versione", ma non riesco ancora a fare clic sull'annuncio. –
Sì, lo era. Hai provato su un altro dispositivo di test? – drk
Ho già trovato una soluzione al mio problema. Ho visualizzato annunci interstitial dopo aver chiamato la funzione finish(). L'applicazione ha mostrato l'annuncio da quando è stato caricato prima, ma l'applicazione era già sparita, quindi il clic non ha funzionato. –