Status bar notification for web app with PhoneGap

2020-07-22 16:57发布

问题:

I am developping a web app for iOS and Android, using the last version of PhoneGap.

I want to send Notifications to the users on their phone's status bar, and I cannot figure out how to do that. It seems that there was a Cordova plugin (StatusBarNotification) that once existed, but all the links I find are dead.

If anyone knows a way to send notif to the statusbar, I would be grateful.

Thanks

Quentin

EDIT : I should have been more specific : I am trying to understand how to use the status area on phones (http://developer.android.com/guide/topics/ui/notifiers/notifications.html), and for that I have a simple html file with a button. I want a notification to appear on the status area when I click the button. (like when you receive a text message, you have a notification).

<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8" />
        <meta name="format-detection" content="telephone=no" />
        <meta name="viewport" content="user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1, width=device-width, height=device-height, target-densitydpi=device-dpi" />
        <link rel="stylesheet" type="text/css" href="css/index.css" />
        <title>Hello World</title>
    </head>
    <body>
        <input type="button" value="Notiiiiiiif" id="btNotif"/>
        <script type="text/javascript" src="cordova.js"></script>  
        <script type="text/javascript" src="js/index.js"></script>

        <script type="text/javascript">
            app.initialize();
            btNotif = document.getElementById('btNotif');
            btNotif.addEventListener('click', function(){
                //There I want a notif to appear in the status bar
            });
        </script>
    </body>
</html>

I am testing this app on my Nexus 4, with Android 4.4.2.

EDIT : I ended up using Google Cloud Messaging (gcm) for android devices and Apple Push Notification (apn) on my node server. This works pretty well with android devices, a bit harder for iphones

回答1:

Perhaps its already to late for the answer, but I think this would make sence for your furhter work with notifications in PhoneGap. For using StatusBarNotifications in latest versions of PhoneGap (v3.x), you need to a proper Plugin that will work. This should be installed with Cordova CLI.

For the older versions of PhoneGap (v2.9 and below) you still can use DEPRECATED version of StatusBarNotifications from GitHub.

By the way, using of older version is less headache for not experienced developers :)

Hope this will help you.