アプリが既に実行中または開いているときに、プッシュ通知を受信できないのはなぜですか? プッシュプラグインを使用しています。これが私のコードです:
<script>
var tokenID = "";
document.addEventListener("deviceready", function(){
//Unregister the previous token because it might have become invalid. Unregister everytime app is started.
// window.plugins.pushNotification.unregister(successHandler, errorHandler);
if(intel.xdk.device.platform == "Android")
{
//register the user and get token
window.plugins.pushNotification.register(
successHandler,
errorHandler,
{
//project ID from Google Cloud Messaging
"senderID":"749289157135",
//callback function that is executed when phone recieves a notification for this app
"ecb":"onNotification"
});
}
}, false);
//app given permission to receive and display push messages in Android.
function successHandler (result) {
// alert('result = ' + result);
}
//app denied permission to receive and display push messages in Android.
function errorHandler (error) {
alert('error = ' + error);
}
//fired when token is generated, message is received or an error occured.
function onNotification(e)
{
switch( e.event )
{
//app is registered to receive notification
case 'registered':
if(e.regid.length > 0)
{
// Your Android push server needs to know the token before it can push to this device
// here is where you might want to send the token to your server along with user credentials.
// if(localStorage.getItem('deviceID') != "" || localStorage.getItem("deviceID") != NULL || localStorage.getItem("puID") !="" || localStorage.getItem("puID") != NULL){
// window.location = "emergencyCode.html";
// }
// else{
tokenID = e.regid;
localStorage.setItem("deviceID", tokenID);
window.location = "start.html";
}
break;
case 'message':
if ( e.foreground ) {
alert("foreground");
} else {
if ( e.coldstart ) {
// window.location = "login.html";
alert('name = ' + e.payload.name);
alert('lat = ' + e.payload.lat);
alert('lng = ' + e.payload.lng);
} else {
alert("BACKGROUND NOTIFICATION");
}
}
break;
case 'error':
alert('GCM error = '+e.msg);
break;
default:
alert('An unknown GCM event has occurred');
break;
}
}
</script>