19

Possible Duplicate:
How can I get device ID for Admob

I am testing adMob on my android device and following with documentation, I am trying to get device ID executing adRequest. However, I am not able to find device ID in the logCat! What I am doing wrong?

 AdRequest adRequest = new AdRequest();
 adRequest.addTestDevice(AdRequest.TEST_EMULATOR);            
 adRequest.addTestDevice("test");     

Edit: it is not a duplicate, those methods from other post are not working for me.

Community
  • 1
  • 1
Jaume
  • 3,672
  • 19
  • 60
  • 119
  • I am running it on my device! – Jaume Mar 13 '12 at 09:37
  • For advertising purposes, you may only use the dedicated advertising ID from Google Play services. Otherwise, you may use [this library](https://github.com/delight-im/Android-BaseLib) to generate either a unique ID per device with [Identity.getDeviceId(context)](https://github.com/delight-im/Android-BaseLib/blob/master/Source/src/im/delight/android/baselib/Identity.java) or an identifier for your app installation via [Identity.getInstallationId(context)](https://github.com/delight-im/Android-BaseLib/blob/master/Source/src/im/delight/android/baselib/Identity.java). – caw Mar 08 '15 at 22:33

3 Answers3

35

Make a live ad request while running on the device, and view the logs. There should be a log at the info level that says:

I/Ads: To get test ads on this device, call adRequest.addTestDevice("YOUR_HASHED_DEVICE_ID");

Since the SDK hashes your device ID, it is much easier and cleaner to grab this number directly through the logs rather than bothering to try to grab the Android device ID, and doing some manual hashing to try to get this same number.

Eric Leichtenschlag
  • 8,881
  • 1
  • 28
  • 28
  • 1
    Your solution looks good but I still receive no log related to ID! – Jaume Mar 14 '12 at 07:47
  • What SDK version are you using (I assume 4.3.1)? When you're checking for logs, are you filtering out info level statements? Are you seeing other logs with the `Ads` tag? – Eric Leichtenschlag Mar 14 '12 at 17:05
  • 2
    Aha! I figured it out. If you **already have** "ads:testDevices=" in your layout XML file, AdMob will NOT print the "to get test ads on this device..." message in the logcat output. Take that out, and then you will see the logcat message. – Andy Dennie Dec 13 '12 at 16:43
28
 final TelephonyManager tm =(TelephonyManager)getBaseContext().getSystemService(Context.TELEPHONY_SERVICE);

String deviceid = tm.getDeviceId();
Pradeep Sodhi
  • 2,135
  • 1
  • 19
  • 19
7

In android < 4

How to find serial number of Android device?

In the new Android 4.0+ you can find the id number in the Settings --> Developer Options

Community
  • 1
  • 1
Aracem
  • 7,227
  • 4
  • 35
  • 72