Android Google Cloud Messaging(GCM)和不匹配的发件人ID [英] Android Google Cloud Messaging (GCM) and missmatched sender id

查看:106
本文介绍了Android Google Cloud Messaging(GCM)和不匹配的发件人ID的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在Android应用中使用GCM服务.

I am trying to use the GCM service in my android app.

为此,我使用了来自 http://developer的android文档. android.com/guide/google/gcm/gcm.html

我使用发件人ID等和服务器端应用程序创建了客户端注册过程,我在其中使用注册ID和发件人ID发送消息.

I created the client side registration process with the sender id etc and the server side application where I am using the registration id and the sender id to send messages.

当我通过Eclipse在手机中安装应用程序时,推送通知可以正常工作,因此我拥有的发件人ID是正确的.

When I am installing the app in my phone through Eclipse, the push notifications works fine, so the sender id i have is right.

然后,当我使用Eclipse导出apk文件并将其安装在手机中时,我收到了SenderId错误的错误消息

Then, when i export the apk file with Eclipse and install it in my phone, I am getting the error message that the SenderId is wrong

MissmatchedSenderId

任何人都知道为什么我要得到这个.

Anyone has an idea whyI am getting this.

我已经阅读了这些主题:

I have read those topics:

为什么我会收到"MismatchSenderId"从GCM服务器端开始?

使用GCM发送邮件时,响应'MismatchSenderId'

但是对于我来说,奇怪的是,在将应用程序导出为apk之前,一切正常,然后出现了这个问题.

But the strange thing in my case is that everything works fine before exporting the app as apk and then I have this problem.

任何想法都很好.

推荐答案

我实际上也遇到了同样的问题,并且进行了10多个小时的研究.

I actually had the same problem, and was researching more than 10 hours.

我终于发现了问题! 与服务器API密钥或浏览器API密钥或SenderID无关. 问题是Google文档:

I finally found out the problem! Nothing related to the Server API key or Browser API Key or SenderID. The problem was the Google documentation:

final String regId = GCMRegistrar.getRegistrationId(this);
if (regId.equals("")) {
  GCMRegistrar.register(this, SENDER_ID);
} else {
  Log.v(TAG, "Already registered");
}

Google表示,只有在ID为空的情况下,您才必须调用getRegistrationId函数! 这对我根本不起作用...当我这样做时,在发送到此regId时,我总是会得到MismatchSenderId.

Google says that you have to call the getRegistrationId function and only if the id is empty call register! Which did not work for me at all... when I did that I always got back MismatchSenderId when sending to this regId.

我的解决方案是: 一律致电

My solution was: Always call

GCMRegistrar.register(this, SENDER_ID);

以及何时功能

protected void onRegistered( Context c, String regId )

称为将regId保存在我的服务器数据库中.

is called save the regId in my server database.

如果我这样做,一切正常!

if I do it this way, all works fine!

这篇关于Android Google Cloud Messaging(GCM)和不匹配的发件人ID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆