修改angularjs个pushnotification的通知
modify the notification of angularjs pushnotification
我正在尝试使用 angularjs、cordova 和 pushplugin 在 android 上添加推送通知。
我收到通知,但我想在显示状态栏通知之前更改收到的数据内容。
例如我用服务器发送类似的东西:
书名:我来晚了
留言:发件人555-555555
是否可以像 WhatsApp 一样更改带有联系人姓名的号码?
拥有类似的东西:
书名:我来晚了
消息:发件人 John Doe
这是我的代码:
window.onNotification = function(e) {
switch( e.event )
{
case 'registered':
if ( e.regid.length > 0 )
{
console.log("Your regID is : " + e.regid);
}
break;
case 'message':
e.message = "message changed";
// this is the actual push notification. its format depends on the data model from the push server
if ( e.foreground )
{
alert("foreground alert");
console.log("foreground log");
}
else
{ // otherwise we were launched because the user touched a notification in the notification tray.
if ( e.coldstart )
{
alert("cold start notif");
console.log("cold start notif");
}
else
{
alert("cold start notif nop" );
console.log("cold start notif nop");
}
}
console.log('message = '+e.message);
alert("GCM message received " + JSON.stringify(e.message));
alert(JSON.stringify(e));
angular.element(document.querySelector('#yata')).html(e.message);
break;
case 'error':
console.log('GCM error = '+e.msg);
break;
default:
console.log('An unknown GCM event has occurred');
break;
}
};
使用此代码,警告框中的消息会被正确更改,但当应用程序处于后台或关闭时,收到的通知不会被修改。
提前致谢!
我认为这不可能直接来自 Cordova。
您应该实现自己的 GcmListenerService to intercept push messaging events and then show your custom notification using the NotificationManager。
我正在尝试使用 angularjs、cordova 和 pushplugin 在 android 上添加推送通知。
我收到通知,但我想在显示状态栏通知之前更改收到的数据内容。
例如我用服务器发送类似的东西:
书名:我来晚了
留言:发件人555-555555
是否可以像 WhatsApp 一样更改带有联系人姓名的号码?
拥有类似的东西:
书名:我来晚了
消息:发件人 John Doe
这是我的代码:
window.onNotification = function(e) {
switch( e.event )
{
case 'registered':
if ( e.regid.length > 0 )
{
console.log("Your regID is : " + e.regid);
}
break;
case 'message':
e.message = "message changed";
// this is the actual push notification. its format depends on the data model from the push server
if ( e.foreground )
{
alert("foreground alert");
console.log("foreground log");
}
else
{ // otherwise we were launched because the user touched a notification in the notification tray.
if ( e.coldstart )
{
alert("cold start notif");
console.log("cold start notif");
}
else
{
alert("cold start notif nop" );
console.log("cold start notif nop");
}
}
console.log('message = '+e.message);
alert("GCM message received " + JSON.stringify(e.message));
alert(JSON.stringify(e));
angular.element(document.querySelector('#yata')).html(e.message);
break;
case 'error':
console.log('GCM error = '+e.msg);
break;
default:
console.log('An unknown GCM event has occurred');
break;
}
};
使用此代码,警告框中的消息会被正确更改,但当应用程序处于后台或关闭时,收到的通知不会被修改。 提前致谢!
我认为这不可能直接来自 Cordova。
您应该实现自己的 GcmListenerService to intercept push messaging events and then show your custom notification using the NotificationManager。