views:

1431

answers:

3

Hello, first time poster here.

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?

+1  A: 

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.

Marcin Gil
That's a good idea. Is there a way to get the number of the emulator programmatically?
Janne
+3  A: 

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.

dar
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.
Janne