I am developing an android app which can able to get push notifications. But I need to have a deviceId to make it successful and as I don't have any android phone, I used to test the app in emulator. So my question is, can I get a deviceId for my emulator.
Asked
Active
Viewed 2.7k times
5
-
do you mean ANDROID_ID? http://stackoverflow.com/questions/4402262/device-identifier-of-android-emulator – kingston Jan 07 '12 at 12:50
6 Answers
5
you can't get device id in android but you can get IMEI number for push notification. bcoz all devices has different IMEI number. In Emulator you get by default 0000000000000 As your IMEI but in device you get perfect number. below is the code to get IMEI number
TelephonyManager telephonyManager1 = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
String imei = telephonyManager1.getDeviceId();

Harsh Trivedi
- 1,012
- 8
- 25
-
-
but consider that tablet with no mobile data connection do not have an IMEI – kingston Jan 08 '12 at 14:02
3
The command 'adb devices' also lists the active emulators, which can give the device id.

Deepak
- 1,101
- 9
- 14
1
Use this method, this works for Tablet and Phone both
public String getDeviceID(Context context) {
TelephonyManager manager =
(TelephonyManager)context.getSystemService(Context.TELEPHONY_SERVICE);
String deviceId;
if (manager.getPhoneType() == TelephonyManager.PHONE_TYPE_NONE) {
//Tablet
deviceId = Secure.getString(this.getContentResolver(),
Secure.ANDROID_ID);
} else {
//Mobile
deviceId = manager.getDeviceId();
}
return deviceId;
}

Ashish Dwivedi
- 8,048
- 5
- 58
- 78
1
This works for me
public static String getIMEI() {
String IMEI = Settings.Secure.getString(getApplicationContext().getContentResolver(),Settings.Secure.ANDROID_ID);
return IMEI;
}

Mehdi Khademloo
- 2,754
- 2
- 20
- 40
1
Through the Android emulators:
- Click the "More" dots at the bottom of the side menu.
- Go to "Help" section at bottom of navigation panel on the left.
- Inside "Help" go to the "About" Tab.
- Here you will find the serial number. Which in some cases is called the "deviceId".

Christopher Chalfant
- 523
- 1
- 6
- 17
0
To get the device Id of your emulator >>>
Inside onCreate() method add this two line :
String android_id = Settings.Secure.getString(this.getContentResolver(), Settings.Secure.ANDROID_ID);
String deviceId = md5(android_id).toUpperCase();
Log.i("device id=",deviceId);
outside the onCreate() method add this md5() method :
public String md5(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++)
hexString.append(Integer.toHexString(0xFF & messageDigest[i]));
return hexString.toString();
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
}
return "";
}
To find the device id just run the app and open the logcat in your android studio and tap in the search bar " device id "

jenos kon
- 504
- 4
- 7