Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/svn/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Cordova 如何使用phonegap for android设置推送通知_Cordova_Push Notification - Fatal编程技术网

Cordova 如何使用phonegap for android设置推送通知

Cordova 如何使用phonegap for android设置推送通知,cordova,push-notification,Cordova,Push Notification,我现在正在开发一个android应用程序,我正在尝试添加推送通知。我浏览了几个论坛,试图调试我的代码以检索我的设备id,这样我就可以开始发送推送通知了。我正在下面粘贴我的代码 提前谢谢你 index.html的头 <script> var pushNotification; pushNotification = window.plugins.pushNotification; // iOS function onNotificationAPN(event) {

我现在正在开发一个android应用程序,我正在尝试添加推送通知。我浏览了几个论坛,试图调试我的代码以检索我的设备id,这样我就可以开始发送推送通知了。我正在下面粘贴我的代码

提前谢谢你

index.html的头

    <script>
    var pushNotification;

pushNotification = window.plugins.pushNotification;

// iOS
function onNotificationAPN(event) {
    if (event.alert) {
        navigator.notification.alert(event.alert);
    }

    if (event.sound) {
        var snd = new Media(event.sound);
        snd.play();
    }

    if (event.badge) {
        pushNotification.setApplicationIconBadgeNumber(successHandler, event.badge);
    }
}


// Android
function onNotificationGCM(e) {
    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.
                alert('registration id = e.regid');
            }
        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>');

                // if the notification contains a soundname, play it.
                var my_media = new Media("/android_asset/www/"+e.soundname);
                my_media.play();
            }
            else    // otherwise we were launched because the user touched a notification in the notification tray.
                $("#app-status-ul").append('<li>--BACKGROUND NOTIFICATION--' + '</li>');

            $("#app-status-ul").append('<li>MESSAGE -> MSG: ' + e.payload.message + '</li>');
            $("#app-status-ul").append('<li>MESSAGE -> MSGCNT: ' + e.payload.msgcnt + '</li>');
        break;

        case 'error':
            alert('GCM error = e.msg');
        break;

        default:
            alert('An unknown GCM event has occurred');
        break;
    }
}

// result contains any message sent from the plugin call
function successHandler (result) {
    alert('result = '+result)
}

// result contains any error description text returned from the plugin call
function errorHandler (error) {
    alert('error = '+error)
}


 function onLoad() {
        document.addEventListener("deviceready", onDeviceReady, false);
            alert('device loaded')

    }

    // Cordova is loaded and it is now safe to make calls Cordova methods
    //

$(document).ready(function() {

    alert('device ready jquery')
        // Now safe to use the Cordova API
 pushNotification.register(successHandler, errorHandler,{"senderID":"uvumobile2012","ecb":"onNotificationGCM"});
})

</script>  
Config.xml

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

<preference name="phonegap-version" value="2.3.0" />
<preference name="orientation"      value="portrait" />
<preference name="target-device"    value="universal" />
<preference name="fullscreen"       value="false" />
<preference name="android-minSdkVersion" value="4" />
<preference name="splash-screen-duration" value="5000" />
<feature name="http://api.phonegap.com/1.0/file"/>
<feature name="http://api.phonegap.com/1.0/geolocation"/>
<feature name="http://api.phonegap.com/1.0/network"/>
<feature name="http://api.phonegap.com/1.0/notification"/>

<gap:plugin name="BarcodeScanner" /> <!-- latest release -->
<gap:plugin name="GAPlugin" /> <!-- latest release -->
<gap:plugin name="PushPlugin" value="com.plugin.GCM.PushPlugin" />

您可以从以下url下载示例应用程序以发送推送通知

您还可以从以下url获得教程