Android emulators with phone numbers?
Asked Answered
T

3

6

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?

Tatiana answered 14/4, 2009 at 6:56 Comment(0)
S
6

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.

Surfacetoair answered 14/4, 2009 at 13:36 Comment(2)
Thanks, the android_id was sort of what I was looking for. However after reading the rest of your answer and thinking more about it I realized I don't want to tie the service strictly to one device.Tatiana
Now it is deprecated and you can use ANDROID_ID defined in Settings.Secure: String id=System.getString(this.getContentResolver(), android.provider.Settings.Secure.ANDROID_ID);Memorabilia
T
3

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.

Tincher answered 14/4, 2009 at 7:40 Comment(1)
That's a good idea. Is there a way to get the number of the emulator programmatically?Tatiana
W
2

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.

Welton answered 23/4, 2013 at 17:51 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.