状态栏通知,phonegap pushplugin

时间:2015-06-08 10:21:46

标签: android cordova

我正在使用phonegap实现一个Android应用程序,我正在使用PushPlugin插件进行通知。到目前为止,我只有锁定屏幕上的警报消息和通知。我想在状态栏中有一个横幅,就像图像中的横幅一样。

图片:http://postimg.org/image/ebipw0s49/

我该怎么做? 这是我的代码:

            onNotification = function (e){
            //        function onNotification(e) {
            $("#app-status-ul").append('<li>EVENT -> RECEIVED:' + e.event + '</li>');

        switch( e.event )
        {
            case 'registered':
            if ( e.regid.length > 0 )
            {

                // Your GCM push server needs to know the regID before it can push to this device
                // here is where you might want to send it the regID for later use.
                $("#app-status-ul").append('<li>REGISTERED -> REGID:' + e.regid + "</li>");
                regid = {'reg':e.regid};
    //                    console.log("regID = " + e.regid);
                //sending the regId to the server
                $.ajax({
                    type:'POST',
                    url:'http://192.168.0.11:5000/api/v1.0/register_id',
                    contentType:'application/json',
                    data:JSON.stringify(regid),
                    success: function(){
                        alert('registration OK');
                    }
                });

            }
            break;

            case 'message':
            // if this flag is set, this notification happened while we were in the foreground.
            // you might want to play a sound to get the user's attention, throw up a dialog, etc.
            if (e.foreground)
            {
                $("#app-status-ul").append('<li>--INLINE NOTIFICATION--' + '</li>');
                alert(e.payload.title + e.payload.message);
                // on Android soundname is outside the payload.
                // On Amazon FireOS all custom attributes are contained within payload
                //var soundfile = e.payload.sound;
                // if the notification contains a soundname, play it.
                // playing a sound also requires the org.apache.cordova.media plugin
                //var my_media = new Media("/android_asset/www/"+ soundfile);
                //my_media.play();
            }
            else
            {   // otherwise we were launched because the user touched a notification in the notification tray.
                if (e.coldstart)
                {
                    $("#app-status-ul").append('<li>--COLDSTART NOTIFICATION--' + '</li>');
                    alert(e.payload.title + e.payload.message);
                }
                else
                {
                    $("#app-status-ul").append('<li>--BACKGROUND NOTIFICATION--' + '</li>');
                    alert(e.payload.title + e.payload.message);
                }
            }
            $("#app-status-ul").append('<li>MESSAGE -> TITLE: ' + e.payload.title + '</li>');
            $("#app-status-ul").append('<li>MESSAGE -> MSG: ' + e.payload.message + '</li>');
            break;

            case 'error':
            $("#app-status-ul").append('<li>ERROR -> MSG:' + e.msg +               '</li>');
            break;

            default:
            $("#app-status-ul").append('<li>EVENT -> Unknown, an event was received and we do not know what it is</li>');
            break;
        }
    }

1 个答案:

答案 0 :(得分:0)

如何显示通知取决于操作系统本身。您正在显示的图像是Android Lollipop(5.0)的通知系统。如果您需要这类通知,请务必将手机更新为Android Lollipop。