我尝试使用以下代码在我的应用中显示全屏广告:
AdRequest.Builder adRequestBuilder = new AdRequest.Builder();
AdRequest adRequest = adRequestBuilder.addTestDevice(AdRequest.DEVICE_ID_EMULATOR).build();
interstitial = new InterstitialAd(this);
interstitial.setAdUnitId(this.getText(R.string.full_screen_ad_unit_id).toString());
interstitial.loadAd(adRequest);
if(interstitial.isLoaded())
{
interstitial.show();
}
但在模拟器和真实设备中,adMob会显示实时广告而不是测试广告。
这会给我带来重大问题,因为它可能会因为无效展示或无效点击而屏蔽我的admob帐户。
我有以下this教程。
那么请帮我解决这个问题?
答案 0 :(得分:0)
我有另一种解决此问题的方法。工作代码是:
AdRequest.Builder adRequestBuilder = new AdRequest.Builder();
AdRequest adRequest;
String android_id = Settings.Secure.getString(this.getContentResolver(), Settings.Secure.ANDROID_ID);
String deviceId = Utilities.getMD5(android_id).toUpperCase(Locale.ENGLISH);
adRequest = adRequestBuilder.addTestDevice(deviceId).build();
boolean isTestDevice = adRequest.isTestDevice(this);
SetLogInfo.writeLog1("is Admob Test Device ? "+deviceId+" "+isTestDevice);
interstitial = new InterstitialAd(this);
interstitial.setAdUnitId(this.getText(R.string.full_screen_ad_unit_id).toString());
interstitial.loadAd(adRequest);
if(interstitial.isLoaded())
{
interstitial.show();
}
getMD5():
protected static String getMD5(String inputText)
{
String md5 = "";
try
{
MessageDigest digester = MessageDigest.getInstance("MD5");
digester.update(inputText.getBytes());
md5 = new BigInteger(1, digester.digest()).toString(16);
}
catch(Exception e)
{
SetLogInfo.writeLog("Exception: "+e);
}
return md5;
}
至少此解决方案最好不要使用" AdRequest.DEVICE_ID_EMULATOR"。从here
得到了想法