device undefined in Android; works in iPhone iOS 8

  • 1
  • Question
  • Updated 5 years ago
Device is not defined on Android, but works on iOS. The geolocation api works on both.

I'm using the Build service. My config.xml has:

App has deviceready run:
alert(device.name);
alert(window.device.name);

The app works on iPhone 5 with iOS 8.4.1. It does not work on HTC One M8 Android 5.0.1 (Lollipop).

"device" is undefined. Any ideas what might be the issue?

Docs:
https://github.com/apache/cordova-plu...
http://docs.phonegap.com/en/1.0.0/pho...
Photo of Caleb Pitman

Caleb Pitman

  • 22 Posts
  • 0 Reply Likes

Posted 5 years ago

  • 1
Photo of Petra V.

Petra V., Champion

  • 7794 Posts
  • 1391 Reply Likes
Probably a timing issue. Are you sure cordova.js has had a chance to load completely?
BTW: 'name' is not a property of the device object, so I can't see how this could "work" in iOS 8.4.1
Photo of Caleb Pitman

Caleb Pitman

  • 22 Posts
  • 0 Reply Likes
I'm using phonegap.js, but it is an alias of cordova.js AFAIK. I'm certain it's working though, since the geolocation plugin works perfectly.

According to the phonegap docs, name is an actual property, but I see it's not in the github docs.

Either way, I actually tested device.uuid which returned an ID on iOS; Android says device is undefined, so there are no properties for it at all.

I can't imagine this would matter, but the Android doesn't have a phone number while the iOS does.

Are there any phone security settings that would prevent phonegap from getting device details?
Photo of Petra V.

Petra V., Champion

  • 7794 Posts
  • 1391 Reply Likes
The phonegap docs you linked to, are ancient (v1.0.0), so maybe device.name is not available anymore.

Are there any phone security settings that would prevent phonegap from getting device details?
That's a good thought. I don't know of any such settings. In this case, I would simply grab another Android test device and test again. If that device returns the uuid (or device.platform, for that matter, since uuid can be spoofed), it's a device specific problem.
Photo of Yi Ming Kuan

Yi Ming Kuan

  • 1840 Posts
  • 78 Reply Likes
Use the latest version of the plugin from the NPM source, and refer to the documentation at https://github.com/apache/cordova-plugin-device/blob/master/README.md

If the issue still persists, post your PhoneGap Build app id here.

-yiming