Reputation: 3005
I could see there is some test id for testing the AdMob ads in Android devices. I know how to get the test id from log cat.
What is the difference in testing the ads in Android devices with the statement adRequest.addTestDevice("TEST_DEVICE_ID");
and without it? Because on both the scenarios I am able to get the ads without any problem.
The code:
AdRequest adRequest = new AdRequest();
adRequest.addTestDevice("TEST_DEVICE_ID");
Upvotes: 4
Views: 8468
Reputation: 2099
Use this:
new AdRequest.Builder()
.addTestDevice(Device.getId(this))
.build();
The Device class:
public class Device {
public static String getId(Context context) {
String deviceId = Settings.Secure.getString(context.getContentResolver(), Settings.Secure.ANDROID_ID);
try {
MessageDigest digest = java.security.MessageDigest.getInstance("MD5");
digest.update(deviceId.getBytes());
byte messageDigest[] = digest.digest();
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);
}
deviceId = hexString.toString();
} catch (NoSuchAlgorithmException e) {
deviceId = "";
} finally {
return deviceId.toUpperCase();
}
}
}
Upvotes: 0
Reputation: 9117
By doing this, you would be loading test ads on your device/emulator.
This is good, since, many times, you might tap on the adverts by mistake, and your account could be banned if this happens regularly or if Admobs decides that you are making those taps deliberately to increase your revenue.
From the docs:
https://developers.google.com/admob/android/targeting#adrequest
Requesting test ads is recommended when testing your application so you do not request invalid impressions. In addition, you can always count on a test ad being available.
Upvotes: 4
Reputation: 5568
"TEST_DEVICE_ID" is just a placeholder for your device unique ID.
It should be replaced with something like:
adRequest.addTestDevice("3E4409D3BCF2XXXXX5D87F53CD4XXXXX");
To find your device ID: Run your app with adRequest.addTestDevice("TEST_DEVICE_ID");
in your code, this would print your device ID to the log. Search the logcat trace for an INFO message containing the text:
adRequest.addTestDevice
Upvotes: 5