虽然我试着对这个问题对方回答,就不能得到解决。 发件人ID是正确的,权限添加,API密钥是真实的。
Although I try other answer about this problem, it can't be solved. Sender ID is correct, permissions are added, API key is true.
我用这篇文章来创建项目: http://developer.android.com/guide/google/gcm/gs.html#server-app
I use this post for creating the project: http://developer.android.com/guide/google/gcm/gs.html#server-app
GCMRegistrar.checkDevice(this);
GCMRegistrar.checkManifest(this);
String regId = GCMRegistrar.getRegistrationId(this);
if (regId.equals("")) {
GCMRegistrar.register(this, SENDER_ID);
regId = GCMRegistrar.getRegistrationId(this);
} else {
Log.v(TAG, "Already registered");
}
String did = getDeviceID();
返回空字符串。
it returns empty string.
你有 GCMIntentService
中定义的 的正确,在你的应用程序的根包?
Do you have GCMIntentService
defined correctly at the root package of your app?
<receiver android:name="com.google.android.gcm.GCMBroadcastReceiver" android:permission="com.google.android.c2dm.permission.SEND" >
<intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
<action android:name="com.google.android.c2dm.intent.REGISTRATION" />
<category android:name="my_app_package" />
</intent-filter>
</receiver>
请确保my_app_package
等同于您的应用程序的主包,或者你的ID将返回一个空字符串。
Make sure that "my_app_package"
is identical to the main package of your app, or your id will return an empty string.
另请注意,
GCMRegistrar.register(this, "...");
是异步的。因此,调用 GCMRegistrar.getRegistrationId(本)
后是不可靠的,所以你应该避免它。
is asynchronous. Therefore, calling GCMRegistrar.getRegistrationId(this)
immediately after that is not reliable, so you should avoid it.
该ID将通过广播回调到达您的 GCMIntentService
,作为注册过程的一部分。从那里,你可以比存储GCM键您想要的位置,并用它在应用程序(通常是服务器)上的其他部分。
The id will arrive via broadcast callback to your GCMIntentService
, as a part of the registration procedure. from there you can than store the gcm key anywhere you like, and use it in other parts of the application (usually on the server).