jQuery Mobile Phonegap Cordova Events not working and Firing

孤街浪徒 提交于 2019-12-13 05:04:47

问题


We have to build a mobile application using HTML5, to be worked on Android and IOS. We started by using jQuery Mobile Framework to manage the pages and actions.Every thing is fine. The problem is when we use the Apache Cordova API, to get some info from the device like the uuid, and manage an Exit Application Button, nothing working!... We use the Cordova Script which get from this Google Link. We put the line below into the config.xml file before building the app pn phonegap:

<plugin name="Notification" value="org.apache.cordova.notification.Notification" />

We use the official documentation presented From Cordova Phonegap Site , which is below:

 <!DOCTYPE html>
<html>
  <head>
    <title>Notification Example</title>

    <script type="text/javascript" charset="utf-8" src="cordova-2.5.0.js"></script>
    <script type="text/javascript" charset="utf-8">

    // Wait for Cordova to load
    //
    document.addEventListener("deviceready", onDeviceReady, false);

    // Cordova is ready
    //
    function onDeviceReady() {
        // Empty
    }

    // alert dialog dismissed
    function alertDismissed() {
        // do something
    }

    // Show a custom alertDismissed
    //
    function showAlert() {
        navigator.notification.alert(
            'You are the winner!',  // message
            alertDismissed,         // callback
            'Game Over',            // title
            'Done'                  // buttonName
        );
    }

    </script>
  </head>
  <body>
    <p><a href="#" onclick="showAlert(); return false;">Show Alert</a></p>
  </body>
</html>

But any thing not happened after building the sources to the Android Platform. No Events fired or anything related to phonegap!

We have searching many results and suggestions to resolve that but without any results!

The applications has been tested on Android 4.3.

Thank you for your suggestions.


回答1:


You are using a very old version of cordova (2.5), the latest version is 3.5 and here is the proper location for documentation and download: http://cordova.apache.org/

Try putting a console.log or alert inside onDeviceReady function to make sure cordova is initialised properly, but I think your problem is with the cordova project setup. Try creating a fresh project using 3.5 with command line as explained in documentation first.




回答2:


Try adding the device plugin from the command line:

phonegap plugin add org.apache.cordova.device

This has worked for me in the past. The command is the same for Windows, Linux and Mac. Then put something into your deviceready event to ensure that it's being fired.




回答3:


Using cordova 2.9.0 and upper cans resolve this issues.

theses lines are needed to put in the config.xml file:

<feature name="Device">
<param name="android-package" value="org.apache.cordova.device.Device" />  // android
<param name="ios-package" value="CDVDevice" /> IOS
</feature>
<!-- -->
<plugins>
<plugin name="App" value="org.apache.cordova.App" />
<plugin name="Device" value="org.apache.cordova.Device" />
<plugin name="Device" value="CDVDevice" />
</plugins>
<!-- phonegap plugins -->
<gap:plugin name="org.apache.cordova.console" />
<gap:plugin name="org.apache.cordova.device" version="0.2.8" />
<gap:plugin name="org.apache.cordova.dialogs" />


来源:https://stackoverflow.com/questions/25579212/jquery-mobile-phonegap-cordova-events-not-working-and-firing

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!