I'm working on a client-server Android application and trying to figure out how to identify different phones/users to the server unambiguously. My first attempt would be to use the phone number on the SIM card. Although now that I think about it, how common is it these days that your phone number changes when you e.g. change carrier? I guess it depends from country to country etc.
Anyway, I've been trying to figure out, since I don't have actual Android phones, how to change the phone number of the emulator phone to simulate different users. Is it possible or should I just think about alternative ways of identification?
The android_id
is supposed to uniquely identify the device, however, it has been noted that the id can be changed if you know how Spoofing android_id
import android.provider.Settings.System;
String android_id = System.getString(this.getContentResolver(), System.ANDROID_ID);
In the emulator, the android_id
does not have a value, so you will need to put a debugging routine in to assign a value yourself.
However, if you want to identify the user, and let the user access your service from different devices with one user id you are better off assigning them a user id and having them authenticate to your service using this user id as their credential. This would let them use their id's on many different devices, unless you used it in conjunction with the android_id
(and the android_id
wasn't spoofed) then you could limit them to one device.
You should use the number present by the emulator. Eg. usually first emulator that is running has number 5554, second 5555, and so on.
You can use these numbers to make calls, send text messages from emulator to emulator. This, I think, simulates different numbers/users for your purposes.
The SIM card info is hard-coded into the emulator-arm and emulator-x86 binaries. Changing the phone number (MSISDN) is detailed at the end of this blog post: new link, web archive
The SIM card stores the phone number with each 2 digits swapped. So (the first 7 of the phone number) 1555521
becomes 515525%d1
in the binary. While a little tedious, patching it for each test isn't the end of the world. You could also use sed:
cd path/to/android-sdk-linux/tools/
cp emulator-arm emulator-arm.backup
sed -i 's/515525%d1/816745%d3/g' emulator-arm
That will change the number to 1-876-543-[PORT NUMBER]. Details on why are in the linked blog post.