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