question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Android - require("tns-core-modules/platform").device.uuid | Cannot read property 'getContentResolver' of undefined

See original GitHub issue

From @cpreston321 on March 18, 2019 16:3

Environment Provide version numbers for the following components (information can be retrieved by running tns info in your project folder or by inspecting the package.json of the project):

  • CLI: 5.2.4
  • Cross-platform modules:5.2.2
  • Android Runtime:5.2.1
  • iOS Runtime:5.2.0
  • Plugin(s): NONE

Describe the bug When you try to recieve the device uuid on Android the app crashes saying that Cannot read property ‘getContentResolver’ of undefined. But IOS works perfectly fine.

To Reproduce Just add this to startup of the project

const platformModule = require("tns-core-modules/platform");

var test = { uuid: platformModule.device.uuid, }; console.log("asdasdasd", JSON.stringify(test));

Expected behavior Supposed to return the uuid of the device.

Sample project https://play.nativescript.org/?template=play-vue&id=v2zJSb&v=1

Additional context I tried logging the platform.android.js file under “tns-core-modules/platform” and logged var nativeApp = appModule.android.nativeApp; came back as undefined so if that could help you debug it faster thanks.

Copied from original issue: NativeScript/NativeScript#7041

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:6 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
tralvescommented, Mar 23, 2019

It will also work if you wrap that code in a setTimeout:

setTimeout(() => {
  var test = {
    model: platformModule.device.model,
    device: platformModule.device.deviceType,
    manufacturer: platformModule.device.manufacturer,
    uuid: platformModule.device.uuid,
    os: platformModule.device.os,
    osVersion: platformModule.device.osVersion,
    sdkVersion: platformModule.device.sdkVersion,
    region: platformModule.device.region,
    screen: {
      heightDIPs: platformModule.screen.mainScreen.heightDIPs,
      heightPixels: platformModule.screen.mainScreen.heightPixels,
      widthDIPs: platformModule.screen.mainScreen.widthDIPs,
      widthPixels: platformModule.screen.mainScreen.widthPixels,
      scale: platformModule.screen.mainScreen.scale
    }
  };

  console.log("asdasdasd", JSON.stringify(test));

});
0reactions
nativescript-vue-botcommented, Apr 7, 2019

We are locking this issue because it has been closed for more than 14 days.

If the issue comes up again please open a new issue with additional details.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Android - require("tns-core-modules/platform").device.uuid
Android - require("tns-core-modules/platform").device.uuid | Cannot read property 'getContentResolver' of undefined #7041.
Read more >
Nativescript app fails to build after including platform.js
Specifically, nativeApp seems to be undefined. I'm running this code thru an Android simulator. What am I missing here? do I need to...
Read more >
ContentResolver | Android Developers
ContentObserver, int) : typically set by a ContentProvider to indicate that this ... specifies which provider should be acquired This value cannot be...
Read more >
cordova-plugin-device
As of Android 9, the underlying native API that powered the uuid property is deprecated and will always return UNKNOWN without proper permissions....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found