How can I get device ID for Admob


I'm using Eclipse to develop applications for android, and I want to integrate Admob to make money. The tutorial says I should watch the LogCat to find ID, but where is it? alt text

When I run in either the test mode or the real mode, sometimes the eclipse will notify that Ads returned, yet it does not show in the emu... can anyone explain?

12/24/2010 6:58:19 AM

Accepted Answer

If you are running admob ads on an emulator then there is no ID. just use the AdManager method and set it to TEST_EMULATOR like the logcat says. If you run on an actual device with usb debugging and watch the logcat, the ID will appear in there.

12/24/2010 8:00:26 AM

The accepted answers will work if you are only testing on the Emulator or on a few devices, but if you are testing on a plethora of devices, you may need some means of prorammatically adding the running device's device ID.

The following code will make the current running device into an adview test device programmatically

    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();
        boolean isTestDevice = mAdRequest.isTestDevice(this);

        Log.v(TAG, "is Admob Test Device ? "+deviceId+" "+isTestDevice); //to confirm it worked

You need to use the md5 of the Android ID, and it needs to be upper case. Here is the md5 code I used

public static final String md5(final String s) {
    try {
        // Create MD5 Hash
        MessageDigest digest =
        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;
        return hexString.toString();

    } catch (NoSuchAlgorithmException e) {
    return "";

EDIT: Apparently that MD5 method isnt perfect, and it was suggested to try I no longer need this feature so I havent tested. Good luck!

Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow