Identify your smartphone in a unique way

5

I have an application that needs to uniquely identify a device.

Even if the user removes and installs the app again, I would like the handle to remain the same.

At first I thought about using the device's IME, but reading documentation , I realized it is not recommended:

  

We recommend following these principles when working with   Android IDs:

     

1: Avoid using hardware identifiers. Hardware identifiers such as SSAID (Android code) and IMEI can be avoided   in most use cases without limiting the resources needed.

I would like to know what is the risk of using IME as the device's unique identifier?

(I believe it is the requested runtime permission of the user)

Is there any other way to uniquely identify the device?

    
asked by anonymous 19.07.2018 / 18:04

2 answers

3

Using MAC Address

I believe that the policies say not to use the IMEI because it can be changed and can be insecure, as "Chinese / pirate" may have IMEI of a non-pirated device and there is also the possibility to change the IMEI. Bandits do it all the time.

In the link you posted you have a solution to your problem, use the device's bluetooth or wifi MAC because it is hardware that is physically attached to the device and much more unlikely to be changed. Plus they have unique identifiers.

The problem with this approach is that it has apparently stopped being available after Android 6.0, but some users seem to have been successful using reflection

private static String getBtAddressViaReflection() {
BluetoothAdapter bluetoothAdapter = BluetoothAdapter.getDefaultAdapter();
Object bluetoothManagerService = new Mirror().on(bluetoothAdapter).get().field("mService");
if (bluetoothManagerService == null) {
    Log.w(TAG, "couldn't find bluetoothManagerService");
    return null;
}
Object address = new Mirror().on(bluetoothManagerService).invoke().method("getAddress").withoutArgs();
if (address != null && address instanceof String) {
    Log.w(TAG, "using reflection to get the BT MAC address: " + address);
    return (String) address;
} else {
    return null;
}

}

More information about this here

Using Android ID

If the MAC solution does not work, there is the possibility of using Android ID, which is a unique identifier for each user, however it can change or return Null after a factory reset.

import android.provider.Settings.Secure;
private String android_id = Secure.getString(getContext().getContentResolver(),Secure.ANDROID_ID);

There are some problems related to this approach, but it seems that most problems have been solved.

Using the phone

  

This approach should not work on devices that do not have   to make calls. Ex: Tablets, TVs, Watches and Vehicles.

If your solution is phone-oriented, you can use TelephoneManager and get the ids / serial and create an identifier:

Add the permission in Manifest:

<uses-permission android:name="android.permission.READ_PHONE_STATE" />

Import the libraries:

import android.content.Context;
import android.telephony.TelephonyManager;
import android.view.View;

And the code ...     final TelephonyManager tm = (TelephonyManager) getBaseContext (). getSystemService (Context.TELEPHONY_SERVICE);

final String tmDevice, tmSerial, androidId;
tmDevice = "" + tm.getDeviceId();
tmSerial = "" + tm.getSimSerialNumber();
androidId = "" + android.provider.Settings.Secure.getString(getContentResolver(), android.provider.Settings.Secure.ANDROID_ID);
UUID deviceUuid = new UUID(androidId.hashCode(), ((long)tmDevice.hashCode() << 32) | tmSerial.hashCode());
String deviceId = deviceUuid.toString();

This solution should return something like 00000000-54b3-e7c7-0000-000046bffd97 .

For more information, see this link

I hope I have helped

    
26.07.2018 / 21:30
2

You can assign a GUID identifier as the chances of it repeating are extremely low.

  

According to this answer in the OS there is a 1% chance of collision if it generates 2,600,000,000,000,000,000 GUIDs.

Reference

    
19.07.2018 / 18:54