1

I compile my Android app using crosswalk, but for some reason I cannot get the device name. I included a reference to the cordova.js file but nothing happens when I use:

alert(device.model)

In AndroidManifest.xml I added this permission:

<uses-permission android:name="android.permission.READ_PHONE_STATE"/>

What else do I need to do?

P.Henderson
  • 1,001
  • 2
  • 13
  • 23

3 Answers3

0

I've never used crosswalk before but in Android if you want to get the model, you'll want to use

Build.MODEL;

Hopefully that works, if not check out the android documentation on Build

AJak
  • 3,863
  • 1
  • 19
  • 28
  • Where in the crosswalk documentation does it say that device.model will work? I know Phone Gap uses device.model but that specific to their platform. Maybe try to utilize something in Navigation. Something like Navigation.platform – AJak May 13 '14 at 20:10
  • Crosswalk is based on Cordova so most things work, I just am not able to get device info. If I emulate my script in Intel XDK I see the device name, but not when I compile it myself and play my app on my phone, so it must be some configuration or permission settings. – P.Henderson May 14 '14 at 14:49
0

device.model does works in Crosswalk build, you also have to include cordova.js.

Here is example code that alerts device.model:

<!DOCTYPE html>
<html>
<head>
    <title>XDK</title>
    <meta name="viewport" content="initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0, user-scalable=0;" />
    <script src="cordova.js"></script>
</head>
<body>
    <button onclick="alert(device.model)">Model</button>
</body>
</html>
krisrak
  • 12,882
  • 3
  • 32
  • 46
  • HI, thank you but that's what I tried, I mentioned this in my question but for some reason it didn't return anything (did not pop the alert at all so no valid variable). – P.Henderson May 15 '14 at 19:08
0

You don't necessarily need to use a Cordova plugin or any hook with Crosswalk. A simple call to

navigator.userAgent

This will output something like

"Mozilla/5.0 (Linux; Android 5.1.1; GT-N7100 Build/LMY47V) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/40.0.2214.91 Mobile Crosswalk/11.40.277.7 Mobile Safari/537.36"

You can see the device model in the output i.e. GT-N7100

Daniel Maclean
  • 779
  • 10
  • 21