Question

I am trying to learn PhoneGap and started creating simple demo. I have just written a code to show alert on page. But its not showing alert at all and showing error of Unable to open asset URL: file:///android_asset/www/cordova_plugins.json.

I have checked out all the answers of SO which are related to the error and also tried but none helped me yet.

UPDATED:

Below is my error:

  03-31 03:18:42.040: E/AndroidProtocolHandler(3710): Unable to open asset URL: file:///android_asset/www/cordova_plugins.json
03-31 03:18:42.220: I/chromium(3710): [INFO:CONSOLE(15)] "Uncaught SyntaxError: Unexpected token :", source: file:///android_asset/www/cordova_plugins.js (15)
03-31 03:18:42.240: I/chromium(3710): [INFO:CONSOLE(56)] "Uncaught module cordova/plugin_list not found", source: file:///android_asset/www/cordova.js (56)
03-31 03:18:45.810: I/chromium(3710): [INFO:CONSOLE(19)] "Uncaught TypeError: Cannot call method 'alert' of undefined", source: file:///android_asset/www/index.html (19)
03-31 03:18:47.010: I/chromium(3710): [INFO:CONSOLE(6725)] "deviceready has not fired after 5 seconds.", source: file:///android_asset/www/cordova.js (6725)
03-31 03:18:47.030: I/chromium(3710): [INFO:CONSOLE(6718)] "Channel not fired: onPluginsReady", source: file:///android_asset/www/cordova.js (6718)
03-31 03:18:47.040: I/chromium(3710): [INFO:CONSOLE(6718)] "Channel not fired: onCordovaReady", source: file:///android_asset/www/cordova.js (6718)
03-31 03:18:47.040: I/chromium(3710): [INFO:CONSOLE(6718)] "Channel not fired: onCordovaConnectionReady", source: file:///android_asset/www/cordova.js (6718)
03-31 03:18:49.950: I/chromium(3710): [INFO:CONSOLE(19)] "Uncaught TypeError: Cannot call method 'alert' of undefined", source: file:///android_asset/www/index.html (19)

Here is my html file:

  <!DOCTYPE HTML>
 <html>
 <head>
 <title> My First PhoneGap App </title>
 <meta name="viewport" content="width=device-width, user-scalable=no"/>
 <meta http-equiv="Content-type" content="text/html; charset=utf-8"/>
<script type="text/javascript" charset="utf-8" src="cordova.js"></script>
<script type="text/javascript" charset="utf-8">

                        var showMessageBox = function() {

                             navigator.notification.alert("Hello World of PhoneGap");

                        }

                        function init(){
                                document.addEventListener("deviceready", showMessageBox, true);     
                               navigator.notification.alert("Hello World of PhoneGap");          

                        }

</script>

 </head>

 <body>
 <h1> Welcome To First PhoneGap Demo </h1>
  <p><a href="#" onclick="init(); return false;">Show Alert</a></p>
  </body>
 </html>

Config.xml

<?xml version="1.0" encoding="UTF-8"?>
<widget xmlns= "http://www.w3.org/ns/widgets"
        xmlns:gap ="http://phonegap.com/ns/1.0"
        id = "com.testdemo.myfirstapp"
        versionCode="1.0"
        version="1.0.0" 
        >

    <name>My First Application </name>
    <description>This is my first demo application</description>

     <feature name="http://api.phonegap.com/1.0/device" />

     <preference name="permissions"       value="none"/>

       <plugin name="NetworkStatus" value="org.apache.cordova.NetworkManager"/>
       <plugin name="Notification" value="org.apache.cordova.Notification"/>
</widget>

enter image description here

As i have added the cordova_plugins.js file in my asset/www/ folder the error of above dialog is gone but it has stopped showing me alert dialog again and showing different error which i have updated in my error log. And if i remove that file it shows me alert message along with the error dialog.

I just do not understand where i am going wrong.

Please help me to solve the issue. Any help will appreciated.

Thanks you.

Was it helpful?

Solution

You have added two plugins . Have your declared in cordova_plugins.js ??

Something like this.

cordova.define('cordova/plugin_list', function(require, exports, module) {
    module.exports = [{
        "file": "plugins/org.apache.cordova.dialogs/www/notification.js",
        "id": "org.apache.cordova.dialogs.notification",
        "merges": ["navigator.notification"]
    }, {
        "file": "plugins/org.apache.cordova.network-information/www/network.js",
        "id": "org.apache.cordova.network-information.network",
        "clobbers": ["navigator.connection", "navigator.network.connection"]
    }];
    module.exports.metadata = // TOP OF METADATA 
    {
        "org.apache.cordova.device": "0.2.8",
        "org.apache.cordova.network-information": "0.2.7"
    }
});

Please check this. http://docs.phonegap.com/en/3.0.0/plugin_ref_spec.md.html

OTHER TIPS

try this one

navigator.notification.alert('Your Alert Message', null, 'Alert', 'OK');
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top