通过GCM向移动设备发送消息时无效注册

时间:2016-05-17 13:06:18

标签: android servlets android-studio push-notification google-cloud-messaging

您好我正在使用GCM为多个移动设备实施推送通知。当我尝试一次运行2个模拟器并通过JSP页面发送消息时,其工作正常。在我的移动设备上安装我的apk文件后,我收到了注册ID,但如果我尝试通过JSP向该特定设备发送消息,则会收到无效注册等错误。我在谷歌搜索但仍然没有得到适当的解决方案来解决我的问题

我在sender.send(message, regIdList, 1);中使用Servlet此语句将消息从JSP页面发送到Android设备。

    Uri sound = RingtoneManager.getDefaultUri(RingtoneManager.TYPE_NOTIFICATION);
    NotificationCompat.Builder noBuilder = new NotificationCompat.Builder(this)
            .setSmallIcon(R.mipmap.ic_launcher)
            .setContentText("My GCM message :X:X")
            .setContentText(message)
            .setAutoCancel(true)
            .setContentIntent(pendingIntent);
    NotificationManager notificationManager = (NotificationManager)getSystemService(Context.NOTIFICATION_SERVICE);
    notificationManager.notify(0,noBuilder.build());

请为我的问题提出一些解决方案

1 个答案:

答案 0 :(得分:0)

regIdList中的内容是什么? 来自GCM的无效注册意味着他们没有您的服务器发送的令牌ID。如果你要从文件中解析它们,可以在空格上尝试trim()吗?