javaandroidcordovatelephonymanagerdeviceid

How to get uuid of android with Java as some other Cordova app did?


I was inspecting a Cordova app which makes API Call to a free open REST API. In one of the POST Requests, it sends the Device Id in a JSON Object. The Device ID in the Cordova App is obtained using:

this.device.uuid;

I am planning to build the same app using Java and hence need to access that Device Id in order to make the API Call. I tried to do the same using the following code.

TelephonyManager tManager = (TelephonyManager)getSystemService(Context.TELEPHONY_SERVICE);
String uuid = tManager.getDeviceId();

But I realized I will need to access READ_PRIVILEGED_PHONE_STATE in Manifest file but that could only be accessed with System App and not a third party one. So how's this Cordova App accessing it?

P.S. - There are chances that this.device.uuid; of the Cordova App might not be returning what I am thinking. So, I will just show you the device Id of my phone by which you might be able to figure out what this is and how to access it in Android using Java. Device Id the Cordova app is getting - 29904bc142b60dce (doesn't change)


Solution

  • The code I mentioned above has now been deprecated. Use the following code:

    String device_id = Settings.Secure.getString(this.getContentResolver(), Settings.Secure.ANDROID_ID);
    

    Also, After Android M; there is different Device ID for every other app. This is what I couldn't figure out and was beating my head over. The app that I developed had some other Device Id in comparison with the app I was comparing it with. So do not expect two different apps in the same device to have the same Device ID.