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 api 29 error getting uuid #36

Open devsgtech opened 4 years ago

devsgtech commented 4 years ago

Exception occurred: getDeviceId: The user 10136 does not meet the requirements to access device identifiers.

Anujmoglix commented 4 years ago

same issue in my case , I am not able to fix that .

TriyogaDibrata commented 4 years ago

i got same issue, any solution?

assafnoahkoren commented 4 years ago

I got this error also, someone managed to find an alternative?

Anujmoglix commented 4 years ago

I think no one is managing it and I am also getting issue with permission . I have added android phone state permission but in many device I am getting null .Anyone have any idea ?

devsgtech commented 3 years ago

You can try this link https://ionicframework.com/docs/native/uid

B0rrA commented 3 years ago

You can try this link https://ionicframework.com/docs/native/uid

The native pluggin of ionic refferes to this same code so...

Anujmoglix commented 3 years ago

Any update ?

stanstanov commented 3 years ago

I have this problem too :(

greaterking commented 3 years ago

Same issue ...will this be updated soon?

greaterking commented 3 years ago

If anyone finds an alternative please post back..thanks.

Anujmoglix commented 3 years ago

I used https://ionicframework.com/docs/v3/native/device/. (uuid of it ) . this is only way to work

greaterking commented 3 years ago

Does the uuid persist across multiple installs?

Anujmoglix commented 3 years ago

yes , I tried with multiple device and multiple install & uninstall . It is working fine and I am using in end user app . I didn't get any issue yet . You should try and check .

greaterking commented 3 years ago

@Anujmoglix Will test and report back ...thanks.

Qsaws commented 3 years ago

I used https://ionicframework.com/docs/v3/native/device/. (uuid of it ) . this is only way to work

I had moved away from that plugin for UUIDs to this one because the UUID didn't persist between installs on iOS, guess i'll have to use both until there is a fix for android on this one.

RameshSenagasetti commented 3 years ago

I managed to solve the issue by updating few lines in UniqueDeviceID.java and things started work as it was before wrt deviceID.

imported android.os.Build to the file.

import android.os.Build;

and updated getDeviceId method as below

protected void getDeviceId(){ > _boolean isAndroid10 = android.os.Build.VERSION.SDK_INT >= android.os.Build.VERSIONCODES.Q; try { Context context = cordova.getActivity().getApplicationContext(); TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);

        String uuid;
        String androidID = Secure.getString(context.getContentResolver(), Secure.ANDROID_ID);
        **_String deviceID;
        String simID;_**

        if ("9774d56d682e549c".equals(androidID) || androidID == null) {
            androidID = "";
        }

        **_uuid = androidID;_**

        **_if ( !isAndroid10 ) {
            deviceID = tm.getDeviceId();
            simID = tm.getSimSerialNumber();
            if (deviceID == null) {
                deviceID = "";
            }
            if (simID == null) {
                simID = "";
            }
            uuid = androidID + deviceID + simID;
        }_**            
        uuid = String.format("%32s", uuid).replace(' ', '0');
        uuid = uuid.substring(0, 32);
        uuid = uuid.replaceAll("(\\w{8})(\\w{4})(\\w{4})(\\w{4})(\\w{12})", "$1-$2-$3-$4-$5");

        this.callbackContext.success(uuid);
    }catch(Exception e ) {
        this.callbackContext.error("Exception occurred: ".concat(e.getMessage()));
    }
}

see if it works for you. (you should remove and add the android platforms again once the plugin is updated with these changes)

greaterking commented 3 years ago

@RameshSenagasetti I can confirm this is working. ~However two things to notes~

~1. getDeviceId is deprecated https://developer.android.com/reference/android/telephony/TelephonyManager#getDeviceId(int)

  1. not sure if the id is persist(is non-resettable) through uninstalls or key signing~

~let me know otherwise.~

greaterking commented 3 years ago

UPDATE

Correction @RameshSenagasetti I see you are only using getDeviceId for everything lower than android 10 which is what is was doing before.

I was under the impression though that you need READ_PRIVILEGED_PHONE_STATE for Android 10 >= ??

greaterking commented 3 years ago

This thread might be useful to the conversation to officially fix this plugin https://stackoverflow.com/questions/4799394/is-secure-android-id-unique-for-each-device

AmilaJJ commented 3 years ago

I am also getting this error. Any updates ?

Adm94 commented 3 years ago

Two of three data used to generate the uniqueId are now no more accessible for Android 10. They are :

See here

So I think the idea of @RameshSenagasetti to only use Secure.ANDROID_ID when the device version is equal or more than Android 10 is good.

But there will be some problem with devices being updated from Android 9 and less to 10 knowing that the generated ID will no more match