admob插页式视频广告是否有测试ID?
我知道横幅和图片插页式广告的虚拟测试ID
横幅:ca-app-pub-3940256099942544/6300978111
插页:CA-应用-PUB-1033173712分之3940256099942544
我需要视频插页式广告的虚拟测试ID
我已经知道如何添加测试设备ID
AdView adView = (AdView)this.findViewById(R.id.adView);
AdRequest adRequest = new AdRequest.Builder()
.addTestDevice(AdRequest.DEVICE_ID_EMULATOR)
.addTestDevice("TEST_DEVICE_ID")
.build();
adView.loadAd(adRequest);
但是我想给其他设备ID未知的人提供演示
所以有人可以给我
提前致谢
答案 0 :(得分:1)
在这里回答:How can I get device ID for Admob
您可以通过编程方式将当前正在运行的设备变为adview测试设备
if(YourApplication.debugEnabled(this)) //debug flag from somewhere that you set
{
String android_id = Settings.Secure.getString(this.getContentResolver(), Settings.Secure.ANDROID_ID);
String deviceId = md5(android_id).toUpperCase();
mAdRequest.addTestDevice(deviceId);
boolean isTestDevice = mAdRequest.isTestDevice(this);
Log.v(TAG, "is Admob Test Device ? "+deviceId+" "+isTestDevice); //to confirm it worked
}
你需要使用Android ID的md5,它需要是大写的。这是我使用的md5代码
public static final String md5(final String s) {
try {
// Create MD5 Hash
MessageDigest digest = java.security.MessageDigest
.getInstance("MD5");
digest.update(s.getBytes());
byte messageDigest[] = digest.digest();
// Create Hex String
StringBuffer hexString = new StringBuffer();
for (int i = 0; i < messageDigest.length; i++) {
String h = Integer.toHexString(0xFF & messageDigest[i]);
while (h.length() < 2)
h = "0" + h;
hexString.append(h);
}
return hexString.toString();
} catch (NoSuchAlgorithmException e) {
Logger.logStackTrace(TAG,e);
}
return "";
}