【发布时间】:2014-03-04 19:19:57
【问题描述】:
我在我的 Android 设备上收到通知。我的 cotification 消息内容显示:
我正在使用 PushPlugin (https://github.com/phonegap-build/PushPlugin) 项目来构建我的代码。
我的 NotificationController.js 代码的一部分是:
registerDevice: function() {
var pushNotification = window.plugins.pushNotification;
if (device.platform == 'android' || device.platform == 'Android') {
pushNotification.register(AppDemo.app.getControllerInstances()['AppDemo.controller.NotificationController'].recieveGCMRegistrationId,
AppDemo.app.getControllerInstances()['AppDemo.controller.NotificationController'].errorHandler,
{"senderID":"624986650855","ecb":"AppDemo.app.getControllerInstances()['AppDemo.controller.NotificationController'].onNotificationGCM"});
}
},
recieveGCMRegistrationId: function(result) {
AppDemo.app.getControllerInstances()['AppDemo.controller.NotificationController'].handleRegistrationId(result, 'GCM');
},
onNotificationGCM: function(event)
{
switch( event.event ) {
case 'registered':
alert("regd id"+event.regid);
this.handleRegistrationId(event.regid, 'GCM');
break;
case 'message':
alert('Notification Received');
break;
case 'error':
alert('Error received from GCM Server : ' + error);
break;
default:
break;
}
},
handleRegistrationId: function (registrationId, deviceType)
{
window.localStorage.setItem("registrationId", registrationId);
}
我的服务器正在发送 JSON 字符串以及 GCM 通知,格式如下:
{"taskName”:" test task name","taskType":" Adhoc Task","taskDescription":"test task description"}
我的 Android 构建项目中的 GCMIntentService.java 中的代码是:
public void createNotification(Context context, Bundle extras)
{
NotificationManager mNotificationManager = (NotificationManager) getSystemService(Context.NOTIFICATION_SERVICE);
String appName = getAppName(this);
Intent notificationIntent = new Intent(this, PushHandlerActivity.class);
notificationIntent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_CLEAR_TOP);
notificationIntent.putExtra("pushBundle", extras);
PendingIntent contentIntent = PendingIntent.getActivity(this, 0, notificationIntent, PendingIntent.FLAG_UPDATE_CURRENT);
NotificationCompat.Builder mBuilder =
new NotificationCompat.Builder(context)
.setSmallIcon(context.getApplicationInfo().icon)
.setWhen(System.currentTimeMillis())
.setContentTitle(appName)
.setTicker(appName)
.setContentIntent(contentIntent);
String message = extras.getString("message");
if (message != null) {
mBuilder.setContentText(message);
} else {
mBuilder.setContentText("<missing message content>");
}
String msgcnt = extras.getString("msgcnt");
if (msgcnt != null) {
mBuilder.setNumber(Integer.parseInt(msgcnt));
}
mNotificationManager.notify((String) appName, NOTIFICATION_ID, mBuilder.build());
tryPlayRingtone();
}
我怎样才能将通知的消息内容从
我想要的类型是:
请在这种情况下帮助我。
任何帮助将不胜感激...
:)
【问题讨论】:
-
您用于从服务器发送消息的代码在哪里?
-
其实,我在客户端开发团队。我的服务器端团队告诉我,他们正在发送上述给定格式的 json 字符串,我必须在消息内容中显示。
标签: android cordova push-notification sencha-touch google-cloud-messaging