1x2x3x4x
1x2x3x4x

Reputation: 604

Can't get devices language in phonegap

I'm doing this exact example from the phonegap docs.

<!DOCTYPE HTML>
<html>
<head>
<title>getPreferredLanguage Example</title>
<script type="text/javascript" charset="utf-8" src="cordova.js"></script>
<script type="text/javascript" charset="utf-8">

function checkLanguage() {
  navigator.globalization.getPreferredLanguage(
    function (language) {alert('language: ' + language.value + '\n');},
    function () {alert('Error getting language\n');}
  );
 }
 </script>
 </head>
 <body>
 <button onclick="checkLanguage()">Click for language</button>
 </body>
 </html>

When I click the button I want it to return the language I'm using on my phone. It works good if I run it through the PhoneGap app, while connected to the local server on my computer (phonegap serve) however it won't work after making the .apk and installing it on my phone. What am I missing?

edit: here's the config.xml http://pastebin.com/t6fx3jRD

<?xml version='1.0' encoding='utf-8'?>
<widget id="com.phonegap.helloworld" version="1.0.0"
 xmlns="http://www.w3.org/ns/widgets"
 xmlns:gap="http://phonegap.com/ns/1.0">
<name>hi bi</name>
<description>
    sample stuff
</description>
<author email="[email protected]" href="http://phonegap.com">
    PhoneGap Team
</author>
<content src="index.html" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<preference name="phonegap-version" value="3.3.0" />
<preference name="permissions" value="none" />
<preference name="orientation" value="default" />
<preference name="target-device" value="universal" />
<preference name="fullscreen" value="true" />
<preference name="webviewbounce" value="true" />
<preference name="prerendered-icon" value="true" />
<preference name="stay-in-webview" value="false" />
<preference name="ios-statusbarstyle" value="black-opaque" />
<preference name="detect-data-types" value="true" />
<preference name="exit-on-suspend" value="false" />
<preference name="show-splash-screen-spinner" value="true" />
<preference name="auto-hide-splash-screen" value="true" />
<preference name="android-installLocation" value="auto" />
<icon src="icon.png" />
</widget>

Upvotes: 0

Views: 113

Answers (1)

user3255670
user3255670

Reputation:

I don't see any obvious problems, but there are five things that should be resolved.

  1. you need to post your config.xml to this forum. If you delete that pastebin file, others will not be able to benefit from this. (If we can get it to work.)
  2. you are using the generic file, which is not a bad thing, except the large file makes it more difficult to spot a problem.
  3. you did NOT use <preference name="phonegap-version" value="X.X.X" />, which is not required. But since you do not, then by default you get the latest version (the bleeding edge) of the phonegap. (This might get you leading edge bugs which would be difficult to debug -- without asking for lots of help.)
  4. Since you are using the latest version of Phonegap, and not 3.3.0, then you should reference leading edge - which does not have an full example.
  5. Since you did NOT say what your target platform is, then perhaps you should look at the Bug List

Lastly, you might consider using an earlier version, say <preference name="phonegap-version" value="3.3.0" />, and try you build again. Oh and RTFM.

Best of Luck, Jesse

Upvotes: 1

Related Questions