Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 387
Sheldon Rong Avatar asked Dec 24 '10 06:12

Sheldon Rong


People also ask

How do I find my AdMob device ID?

On Android devices, you can find your advertising ID in your device settings. Navigate to Settings, click Google, and then Ads: You can also find the advertising ID programmatically.

How do I find my android device ID?

There are several ways to know your Android Device ID 2- Another way to find the ID is by going to the Menu >Settings > About Phone > Status. The IMEI / IMSI / MEID should be present in the phone status setting. 3- The ID could also be below or under the battery or on the back or bottom of the device itself.

Is there any AdMob dummy ID?

Yes. You will need to register your app in your Ad-Mob account.

How long does it take for an AdMob ad unit ID to become active?

Wait up to 24 hours after you create your account. When you first sign up for AdMob, your account is reviewed before it's approved. This typically takes up to 24 hours, but in rare cases can take up to 2 weeks.


4 Answers

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();
        mAdRequest.addTestDevice(deviceId);
        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 = 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 "";
}

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

like image 127
joseph Avatar answered Oct 21 '22 07:10

joseph


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.

like image 21
Phobos Avatar answered Oct 21 '22 09:10

Phobos


  • Is your app published on Play store -- with live ads:

If your app is on Play store showing live ads -- you can't use live ads for testing -- add your device ID in code to get test ads from Admob on your real device. Never use live ads during development or testing.

To get real device ID in logcat,

  1. Connect your device in USB debug mode to Android Studio

USB debug mode(Developer option)

  1. 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.

  2. Filter the logcat with 'device' as shown below to get test device

Test Device ID in logcat

Read Admob ad testing on device - device IDs can change for more

like image 28
AndroidLearner Avatar answered Oct 21 '22 08:10

AndroidLearner


Something similar to Google Ads, from the documentation:

public AdRequest.Builder addTestDevice (String deviceId)

Causes a device to receive test ads. The deviceId can be obtained by viewing the logcat output after creating a new ad. For emulators, use DEVICE_ID_EMULATOR.

for example my Test Device id displayed in LogCat is "B86BC9402A69B031A516BC57F7D3063F":

AdRequest adRequest = new AdRequest.Builder() 
        .addTestDevice(AdRequest.DEVICE_ID_EMULATOR)
        .addTestDevice("B86BC9402A69B031A516BC57F7D3063F")
        .build();
like image 37
Jorgesys Avatar answered Oct 21 '22 07:10

Jorgesys