Paldom / UniqueDeviceID

PhoneGap / Cordova unique device id (UUID) plugin for Android, iOS and Windows Phone 8. Remains the same after app uninstall.
MIT License
169 stars 96 forks source link

Android 10 support #33

Open manelds opened 4 years ago

manelds commented 4 years ago

Hi,

I'm trying to get the serial of a device with Android 10 and it returns "unknown". With older versions of Android, works fine.

I found this link about the new Android version: https://developer.android.com/about/versions/10/privacy/changes

Has someone the same problem?

Many thanks.

mcendon commented 4 years ago

Hi, This is my little contribution.

As I see, in this class https://github.com/Paldom/UniqueDeviceID/blob/master/src/android/UniqueDeviceID.java the deviceId is calculated by this formula (line 77):

uuid = androidID + deviceID + simID;

Since deviceID and simID is not longer supported in Android 10, you only have the androidID to identify the device (as i know, the Android ID is generated by the OS and is unique) and the device ID returned by the plugin will have this structure:

00000000-0000-0000-XXXX-XXXXXXXXXXXX

where XXXX-XXXXXXXXXXXX is the Android ID

In our app we need to mantain compatibity with Android 9 devices and older who are being updated to android 10, so, from the older "complete" device id (containing androidID + deviceID + simID) we take only the first part (androidID) and compare it against the deviceID generated in android 10 for example:

o4ca5327-cd5c-3a0f-3345-181008441738 (old uniqueDeviceID, containing simID and deviceID)

00000000-0000-0000-o4ca-5327cd5c3a0f ("new" Android 10 uniqueDeviceID, containing only Android ID)

We just compare the o4ca-5327cd5c3a0f part to identify the device

I hope it help