3

I have a requirement that if I run my app in one Android device and then try to run the same app in another Android device I need to check first if its another device or not and if it is then I should continue. Could you please tell me if there is any way in which I can achieve this?

Thank you.

Ingrid Cooper
  • 1,191
  • 3
  • 16
  • 27
  • Put a flag in shared preference. On first run of application set the flag. On next run check the flag.Then you will know.. ??? – SKT Feb 06 '13 at 08:54

3 Answers3

2

you can use this:

telephonyManager = (TelephonyManager) getContext().getSystemService(Context.TELEPHONY_SERVICE);
telephonyManager.getDeviceId();
telephonyManager.getSimSerialNumber();

getDeviceId and getSimSerialNumber are unique per device, so you can check this values

Tomer Mor
  • 7,998
  • 5
  • 29
  • 43
  • Where are you going to check the values? I suspect that there is a bit more involved in a successful answer. – paulkayuk Feb 06 '13 at 14:22
  • 1
    you must save this values in server side not in client side, so for the first device you should upload this values and check them against the other devices .. – Tomer Mor Feb 06 '13 at 14:52
0

To Achieve This the problem is this :

How can we differentiate, if we are installing app,
first time on 1st device or first time on second device.
so for that we have to use a unique key for app to run 
on each different device.
So that before saving shared pref,
we can validate the unique key for that device. 

Now Question is that how user will get the unique key? So lets assume application vendor will provide key for each device. but for that, app should have some algorithm to validate the key provided by us.

But Unfortunately, If vendor provide the key, user can use that key to install on another device also.

SO The Final Solution is before first run app Must register device on Some Web Service for Activation.

Shridutt Kothari
  • 7,326
  • 3
  • 41
  • 61
  • 'before the first run app Must register device on Some Web Service' Now that would be Magic! I fear you were closer (or at least one the way) with your first answer. (I do suspect, however, that the idea you have in your head would work, it's just the way you have expressed it in writing that makes it seem magical) – paulkayuk Feb 06 '13 at 15:33
-1

Set a flag in shared preferences in first run

SharedPreferences preferences = getSharedPreferences("PREF_NAME", 0);
boolean onlyonce = preferences.getBoolean("FLAG_NAME", false);

if (!onlyonce ) {
   SharedPreferences.Editor editor = preferences.edit();
   editor.putBoolean("FLAG_NAME", true);
   editor.commit();
}

There is a risk if user resets application it gets cleared also. Will this solve your problem?

SKT
  • 1,821
  • 1
  • 20
  • 32
  • -1 for not reading/understanding the question before answering – paulkayuk Feb 06 '13 at 11:01
  • @paulkayuk Thanks for the comment why you have downvoted. But I have explained the risk in doing so in my answer itself. Still why? – SKT Feb 06 '13 at 12:01
  • Please read the OP question, they are referring to 2 different Devices. Shared Preferences exist on each individual device and are not shared across 2 or more devices. – paulkayuk Feb 06 '13 at 14:13