简体   繁体   中英

Phonegap Notification not working in phonegap developer android app

I am using PhoneGap Developer App to test my app during development. But I can't get the plugins to start working. In this case I am using the notification. JavaScript alert works but notification.alert is not working. Please I have been going around this for days now. Here is what my code looks like.

<script type="text/javascript" src="cordova.js"></script>
<script type="text/javascript" src="js/index.js"></script>
<script type="text/javascript" src="js/jquery.js"></script>
<script type="text/javascript" src="js/responsive.js"></script>
<script type="text/javascript">
    app.initialize();
    if(window.localStorage.getItem('session') == null){
        navigator.notification.alert("Not logged in", null, "Login?", "Continue");
        navigator.notification.beep(1);
        navigator.notification.vibrate(1000);
        //alert('not logged in');
        }else{
            navigator.notification.alert("Logged in", null, "Login?", "Continue");
            navigator.notification.beep(1);
            navigator.notification.vibrate(1000);
            //alert('logged in');
            }
</script>

@ITECH-PLANET,
if you are using the standard example that comes with the PhoneGap Developer App , then you MUST wait until the deviceready has *fired*.

You can test this by putting function section of code in a function, then calling that function.

Like this:

app.notify : function () {
    if(window.localStorage.getItem('session') == null){
        navigator.notification.alert("Not logged in", null, "Login?", "Continue");
        navigator.notification.beep(1);
        navigator.notification.vibrate(1000);
        //alert('not logged in');
    }else{
        navigator.notification.alert("Logged in", null, "Login?", "Continue");
        navigator.notification.beep(1);
        navigator.notification.vibrate(1000);
        //alert('logged in');
        }
}

Then change to this:

<script type="text/javascript">
    app.initialize();
    app.notify();
</script>

For additional details read #4 of Top Mistakes by Developers new to Cordova/Phonegap

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM