AsamK / JodelJS

Unofficial web app for Jodel
GNU General Public License v3.0
32 stars 8 forks source link

Recommended way to get Device UID #2

Closed audacus closed 8 years ago

audacus commented 8 years ago

Hey there

I wanted to set up JodelJS with an existing Device UID. Now I tried to get this 64 characters long hex value from an android device (Settings.Secure.ANDROID_ID). I used following code to get the value: http://stackoverflow.com/a/2785493/3442851

But the value I get is only a 16 characters long hex string.

Do I have to convert this value into a 64 characters long hex value or what is your recommended approach to get this 64 characters long Device UID?

AsamK commented 8 years ago

The device UID used by jodel is the sha256 hash of a device identifier string, that is made up of multiple parts. One of those parts is the ANDROID_ID, it also includes the telephone number and other ids. The following code creates the device identifier (it needs the android.permission.READ_PHONE_STATE permission). To get the device UID, you need to take the sha256 hash of the result.

TelephonyManager telephonyManager = (TelephonyManager) getContext().getSystemService(Context.TELEPHONY_SERVICE);
String clientId = "81e8a76e-1e02-4d17-9ba0-8a7020261b26";
String line1Number = telephonyManager.getLine1Number();
String buildSerial = android.os.Build.SERIAL;
String androidId = Secure.getString(getContext().getContentResolver(), Secure.ANDROID_ID);
String deviceId = telephonyManager.getDeviceId();
String subscriberId = telephonyManager.getSubscriberId();
String simSerialNumber = telephonyManager.getSimSerialNumber();
return clientId + line1Number + buildSerial + androidId + deviceId + subscriberId + simSerialNumber;
audacus commented 8 years ago

Brilliant! Thanks a lot!