如何自定义GCM Message Builder

时间:2013-11-16 08:15:07

标签: java android google-cloud-messaging

我有一切设置,并能够发送接收与gcm。但如何定制收到的通知?

代码:

Message message = new Message.Builder()
.addData("message", "testing")
.build();

模拟器中收到通知: -

GCM Notification 
 Received: Bundle[{message=testing}]

我想更改标题 GCM通知并删除收到的内容。一直在网上搜索,无法找到。谢谢你的帮助。

2 个答案:

答案 0 :(得分:0)

请查看Google提供的此文档,它将向您解释如何将GCM邮件转换为通知:http://developer.android.com/google/gcm/client.html (“收到消息”部分)。

答案 1 :(得分:0)

非常感谢您的提示。傻傻的我,我以为从gcm服务器发送的消息(来自消息构建器)将会在应用程序中发布。

不知道我需要处理从客户端本身收到的消息

private void sendNotification(String msg) {
        mNotificationManager = (NotificationManager)
                this.getSystemService(Context.NOTIFICATION_SERVICE);

        PendingIntent contentIntent = PendingIntent.getActivity(this, 0,
                new Intent(this, DemoActivity.class), 0);

        NotificationCompat.Builder mBuilder =
                new NotificationCompat.Builder(this)
        .setSmallIcon(R.drawable.ic_stat_gcm)
        .setContentTitle("GCM Notification") //this is the place I am looking for
        .setStyle(new NotificationCompat.BigTextStyle()
        .bigText(msg))
        .setContentText(msg);

        mBuilder.setContentIntent(contentIntent);
        mNotificationManager.notify(NOTIFICATION_ID, mBuilder.build());
    }