Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Device identifier of Android emulator

I want to test in the emulator an app that depends of the device identifier (ANDROID_ID).

I currently obtain device identifier with the following code:

final String deviceID = Settings.Secure.getString(context.getContentResolver(), Settings.Secure.ANDROID_ID); 

When I run this in an emulator it returns null, which gives me all sort of problems. It seems that higher Android versions it returns something.

Is there a way to get a device identifier in the Android emulator? Am I obtaining the device id wrongly?

Maybe it's possible to set the device identifier of the emulator through the console?

like image 878
hpique Avatar asked Dec 09 '10 19:12

hpique


People also ask

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.

Does emulator have IMEI number?

The emulator binary is not encrypted nor compressed, so the string literals should be visible inside the emulator binary. In fact they are, and IMEI number can be modified in a few simple steps: backup the emulator binary. open the binary with your favourite hex editor.

What is the Android ID?

The android device ID is a unique alphanumeric code generated for your Android phone when you first set it up. This code basically identifies your device similar to how the IMEI number works. However, Android device ID is specifically used for identification purposes, instead of tracking your device.


2 Answers

In the emulator, the values of IMEI and IMSI are hardcoded:

2325     { "+CIMI", OPERATOR_HOME_MCCMNC "000000000", NULL },   /* request internation subscriber identification number */ 2326     { "+CGSN", "000000000000000", NULL },   /* request model version */ 

therefore, you will always get null.

If you still want to use these id numbers for your testing and you want to keep the same code for the emulator and the real device, you must change it in the emulator somehow.

There are at least two ways how to do it:

  1. Change the values in the code and recompile the code for the emulator. However, this might be too complicated and time consuming... :-)

  2. "Hack" the emulator binary (since it is neither compressed or encrypted - you can do it!) and modify the strings (in the right place) right there.

Here's how to do it:

  • backup the emulator binary (to roll back! later). In Windows, the binary can be found under the name "emulator.exe", located in your android "\tools" folder.

  • open the binary with your favourite hex editor

  • search for the +CGSN string followed by a null byte (it should be followed by 15 digits of the IMEI number - see the printscreen below)

alt text

  • edit the number (be careful not to change the original number of the digits)

  • and save the file!

  • and maybe change/adjust your code to use the IMEI for your id (as Falmari points out), or use this trick to change some other values.

like image 81
StanislavK Avatar answered Sep 27 '22 20:09

StanislavK


If you want non-null emulator uuid, then start the emulator like this:

emulator -avd jbx86 -prop emu.uuid=5ec33f90-a471-11e2-9e96-0800200c9a66 
like image 44
Scott Evernden Avatar answered Sep 27 '22 18:09

Scott Evernden