![](/img/trans.png)
[英]Android notification push empty using GCM and java with json message
[英]GCM Notification shows JSON message
我面临创建GCM通知的问题。 默认情况下,它以JSON形式显示消息。
我想包装我的JSON,只想在通知中显示一些消息,例如说“您收到了新消息”,但是当任何用户单击通知时,其他信息JSON等应可用于客户端应用程序。
使用Java构建GCM服务器应用程序并在tomcat上运行。
我关注了GCM官方网站教程及其演示客户端/服务器应用程序。
[更新]:
Sender sender = new Sender(Constants.SENDER_ID);
androidTargets.add(MY_DEVICE_ID);
Message message = new Message.Builder()
.collapseKey("GCM_Message")
.timeToLive(30)
.delayWhileIdle(true)
.addData("message", msg)
.build();
MulticastResult result = sender.send(message, androidTargets, 3);
System.out.println("GCM message sent");
if (result.getResults() != null) {
int canonicalRegId = result.getCanonicalIds();
if (canonicalRegId != 0) {
}
} else {
int error = result.getFailure();
System.out.println("Broadcast failure: " + error);
}
而'message'是json字符串。
任何帮助将不胜感激。
将您的主题字符串传递给setContentTitle(subject),您可以检查此代码段,它可能会对您有所帮助。
NotificationManager notificationManager = (NotificationManager) parametes.context
.getSystemService(Context.NOTIFICATION_SERVICE);
Intent intent = null;
intent = new Intent(parametes.context, MainActivity.class);
PendingIntent contentIntent = PendingIntent.getActivity(
parametes.context, 0, intent, 0);
NotificationCompat.Builder mBuilder = new NotificationCompat.Builder(
parametes.context)
.setSmallIcon(R.drawable.app_icon)
.setContentTitle("My Subject Line here.")
.setAutoCancel(true);
mBuilder.setContentIntent(contentIntent);
parametes.mNotificationManager.notify(
CheckInboxWithCountParams.NOTIFICATION_ID,
mBuilder.getNotification());
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.