How do I detect another Android device?

I have a requirement that if I run an app on one Android device and then try to run the same app on another Android device, I need to check it first if its a different device or not, and if so, I have to continue. Could you tell me if there is a way that I can achieve this?

Thank.

+3


source to share


3 answers


you can use this:

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

      



getDeviceId

and getSimSerialNumber

are unique for each device, so you can check these values

+2


source


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 the question is, how will the user get the unique key? So let's assume the app vendor provides a key for each device. but for that the application must have some algorithm to validate the key we provided.



Unfortunately, if the vendor provides a key, the user can use that key to install on another device.

SO Final decision before first launching the app It is necessary to register the device with some web services for activation.

0


source


Check the box in general preferences on first launch

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 that the user is resetting the application, which is also cleared. Will this solve your problem?

-1


source







All Articles