Android GCM错误.注册客户端后,服务器返回未注册 [英] Android GCM error. Server returns Not Registered when client IS registered
问题描述
我遵循了 http://developer.android.com/google/上给出的演示gcm/gs.html 并获得了试用版应用程序GCMTrial才能正常工作.
I followed the demo given at http://developer.android.com/google/gcm/gs.html and got a trial application, GCMTrial to work correctly.
但是,我尝试在现有应用程序上执行相同的步骤,但没有成功.所以我做了一个全新的项目.但是即使那样,按照相同的确切步骤,我也无法让GCM成功发送消息.因此,我尝试将GCMTrial重命名为所需的名称,但那也不可行.
But, i tried to follow the same steps on an existing application but it didnot work. So I made an entirely new project. But even then , following the same exact steps, I couldnt get GCM to send a message successfully. So I tried renaming GCMTrial to the required name, and not that too does not work.
我通过主要活动注册了GCM,并获得了以下日志:
I register for GCM via the main activity and get the following log :
12-19 21:30:13.102: V/GCMRegistrar(15889): Registering receiver
12-19 21:30:13.112: D/GCMBaseIntentService(15889): handleRegistration: registrationId = XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX, error = null, unregistered = null
12-19 21:30:13.112: D/GCMRegistrar(15889): resetting backoff for com.XXX.XXX
12-19 21:30:13.117: V/GCMRegistrar(15889): Saving regId on app version 1
但是当我尝试发送GCM消息时,它返回以下错误
But when i try to send a GCM message, it returns the following error
[ errorCode=NotRegistered ]
客户代码:
public class MainActivity extends Activity {
TextView tve;
String TAG = "GCMTrial";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
GCMRegistrar.checkDevice(this);
GCMRegistrar.checkManifest(this);
final String regId = GCMRegistrar.getRegistrationId(this);
if (regId.equals("")) {
GCMRegistrar.register(this, "XXXXXX");
Log.v(TAG, "Reg");
} else {
Log.v(TAG, "Already registered");
}
}
GCMIntentService :
public class GCMIntentService extends GCMBaseIntentService {
@Override
protected void onError(Context arg0, String arg1) {
// TODO Auto-generated method stub
}
@Override
protected void onMessage(Context arg0, Intent arg1) {
// TODO Auto-generated method stub
Log.d("GCM", "RECIEVED A MESSAGE");
// Get the data from intent and send to notificaion bar
}
@Override
protected void onRegistered(Context arg0, String arg1) {
// TODO Auto-generated method stub
}
@Override
protected void onUnregistered(Context arg0, String arg1) {
// TODO Auto-generated method stub
}
}
清单:
Manifest :
服务器代码:
System.out.println("Sending GCM");
String key = "XXX"; //Server API key taken from the site
clientID = "XXXXXXXXX"; // copied from the logs
Sender sender = new Sender(key);
Message message = new Message.Builder().build();
Result result = sender.send(message, clientID, 1);
System.out.println(result.toString());
这让我发疯..它显示为在android手机中注册,甚至调用了GCMIntentService类的onRegistered方法..但是当我尝试发送消息时,它标记为"NotRegistered Error" ... 我不知道我在做什么错..请帮帮我....
It is driving me crazy.. It shows as registered in the android phone, even calls the onRegistered method of the GCMIntentService class.. but when i try to send a message, it flags a "NotRegistered Error" ... I dont know what im doing wrong.. please help me out guys....
推荐答案
好,知道这是使用adb安装时的当前错误.
Well, know it's a current bug when installing with adb.
GCMRegistrar不知道该设备尚未在GCM服务器上注册,也没有注册.
GCMRegistrar does not know that the device is unregistered on GCM server and don't register.
您可以做的还是注册:
if (regId.equals("")) {
GCMRegistrar.register(this, "XXXXXX");
Log.v(TAG, "Reg");
} else {
//I SAY BULLSHIT !
GCMRegistrar.register(this, "XXXXXX");
Log.v(TAG, "Reg");
}
或者在客户端上安装该应用,然后从Adb运行新安装.
Or uninstal the app on client then run a new install from Adb.
请记住,在生产中发生这种情况的可能性很小.
Keep in mind there is few chances it happens in production.
这篇关于Android GCM错误.注册客户端后,服务器返回未注册的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!