Device.uuid undefined in PhoneGap on Android?

I am writing a PhoneGap application that sends requests to a central database. It should be able to identify unique devices that connect to it.

The PhoneGap device.uuid property seems to do the trick. On webOS and iPhone, I am returning a unique string of alphanumeric characters that will satisfy my need. However, the Android devices I tested (Motorola Droid and Android SDK emulator running Android 2.1) return "undefined" as device.uuid .

device.platform and device.name return the correct values ​​on all three platforms, so the problem is not related to the device object itself (it is defined in the code blocks where I use it).

Is this a limitation of Android? Problem with PhoneGap?

Is there any other way to get such a globally unique identifier, if not through device.uuid ?

EDIT: It looks like the deviceready event never fires, which should happen before the device.uuid property becomes available.

+4
source share
4 answers

Depending on the version of Phonegap and / or device, you may need to install the plugin explicitly. There was a device in our project, but device.uuid was undefined. Running cordova plugin add org.apache.cordova.device fixed the problem in our case.

+3
source

I have not yet found a solution for this, but it is worth noting that this problem is fixed in Android 2.2. But besides this, you will have to find another way to get a unique device identifier if the device works both 2.1 and earlier.

+1
source

I had the same problem. It worked earlier, and I eventually traced the issue back to manifest permissions.

If android.permission.ACCESS_NETWORK_STATE not activated, deviceready will not work, and device.uuid will not be available.

0
source

this works for me:

first installation of the device plugin:

 cordova plugin add cordova-plugin-device 

and in my index.js I have this:

 var app = { initialize: function() { $.support.cors = true; this.bindEvents(); }, bindEvents: function() { document.addEventListener('deviceready', this.onDeviceReady, false); }, onDeviceReady: function() { app.receivedEvent('deviceready'); }, receivedEvent: function(id) { console.log('Received Event: ' + id); }, getDeviceInfo: function() { var aio = new Object(); aio.agent = device.platform + "," + device.version + "," + device.model; aio.deviceid = device.uuid; return aio; } }; app.initialize(); module.controller('AppController',function($scope) { console.log('GOOOO'); ons.ready(function() { console.log("ons ready"); var appInfoObj = app.getDeviceInfo(); console.log("Agent: " + appInfoObj.agent); console.log("UUID: " + appInfoObj.deviceid); }); }); 
0
source

Source: https://habr.com/ru/post/1310429/


All Articles