Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to programmatically get the Device ID for Admob?

I have multiple devices, and I probably will have more, and do not want to add them one by one. Does anybody know what ID Admob uses?

like image 388
dongshengcn Avatar asked Mar 09 '11 17:03

dongshengcn


People also ask

How do I Find my AdMob advertising ID?

There are several ways to find an ID to use in your AdMob account to configure your device as a test device. Note that Android devices use the advertising ID and iOS devices use the IDFA. On Android devices, you can find your advertising ID in your device settings. Navigate to Settings, click Google, and then Ads:

How do I add a device to my AdMob account?

Click Add test device. Select the platform of your device. Enter a device name. Consider using a name that will help you quickly identify your devices in your AdMob account. Note: The device name will be visible to anyone who has access to your AdMob account.

What is a test device in the AdMob network?

Setting up a test device lets you safely test production ads and verify your implementation code without violating AdMob’s invalid traffic policy. When you configure your Android or iOS device as a test device, the AdMob Network sends production ads in test mode to your device using the ad unit IDs you've created in your AdMob account.

How do I enable AdMob live ads on Android Studio?

Connect your device in USB debug mode to Android Studio Open any app on your device which shows live ads from Admob:On the connected device, if you have your app downloaded from play store(showing live ads) open that app or else open any other app that shows live Admob ads. Your device should have an internet connection.


1 Answers

String aid = Settings.Secure.getString(getContext().getContentResolver(), "android_id");

Object obj = null;
try {
    ((MessageDigest) (obj = MessageDigest.getInstance("MD5"))).update(
                                   aid.getBytes(), 0, aid.length());

    obj = String.format("%032X", new Object[] { new BigInteger(1,
                                   ((MessageDigest) obj).digest()) });
} catch (NoSuchAlgorithmException localNoSuchAlgorithmException) {
    obj = aid.substring(0, 32);
}

I hope this will help you ;)

like image 139
user1120696 Avatar answered Sep 27 '22 21:09

user1120696