我尝试迁移到GCM,我有一个问题,与SENDER_ID我需要提供.我使用谷歌的演示项目.在这个项目中,如果我理解这一点,我需要SENDER_ID在CommonUtilities.java文件中为应用程序提供一个.
我提供的SENDER_ID是我在https://code.google.com/apis/console/上注册的API密钥,其格式为:( AIzaSyAxxxxxxx_xxxxxxxxxxxnoGZw共40个字符).
当SENDER_ID我在"BroadcastReceiver mHandleMessageReceiver"上使用此字符串时出现错误消息:来自GCM:错误(INVALID_SENDER)..
哪里出错了?我提供的字符串不是SENDER_ID?
谢谢.
我在一个神秘的问题上停留了一段时间.所以我在我的Android应用程序中实现了GCM,但是我收到了INVALID_SENDER错误.
关于这一点的奇怪之处在于我已经有一个注册ID来发送通知.所以我的控制台看起来像这样:
03-26 09:39:20.233: I/<test>(19761): Already registered: APA91bG6- O3OnZt50EAjYvJ5KETv3qAlPOn2SfOPXez7SLAmaAOkHTN6EMDJb91gFIWkftZkJiub6UoEk4O- WQP7kk2oZGQjZ1VCZZS0WddQtjFaCfYfZfb7SEw3IS1sd4caJcdZE4LA1F0hxzc7Ss1UiYHXX-XXXX
03-26 09:48:23.522: I/<test>(19925): GCMIntentService
03-26 09:39:20.670: I/<test>(19761): on Error INVALID_SENDER
Run Code Online (Sandbox Code Playgroud)
在onCreate里面:
GCMRegistrar.checkDevice(this);
GCMRegistrar.checkManifest(this);
final String regId = GCMRegistrar.getRegistrationId(this);
if (regId.equals("")) {
Log.i("<test>", "registering");
GCMRegistrar.register(this, "2194354949XX");
} else {
Log.i("<test>", "Already registered: " + regId);
}
Run Code Online (Sandbox Code Playgroud)
广播接收器:
public class GCMBroadcastReceiver extends com.google.android.gcm.GCMBroadcastReceiver{
@Override
protected String getGCMIntentServiceClassName(Context context){
return "be.XXX.XXX.system.GCMIntentService";
}
}
Run Code Online (Sandbox Code Playgroud)
GCMIntentService:
public class GCMIntentService extends GCMBaseIntentService {
@Override
protected void onError(Context arg0, String errorId) {
Log.i("<test>","on Error " …Run Code Online (Sandbox Code Playgroud) 我继承了一个已经实现了GCM服务的应用程序并且运行良好.
我说的很好,因为有一半时间,当应用程序启动时,我得到错误INVALID_SENDER而另一半我得不到它!
我得到错误的时间和我没有得到的时间之间没有区别(或者我可能错过了差异).
我不时从GCM收到消息(当我INVALID_SENDER登录后没有得到)
这是onCreate()我主要活动中的注册码
private void registerGCM() throws Exception {
GCMRegistrar.checkDevice(this);
GCMRegistrar.checkManifest(this);
registerReceiver(mHandleMessageReceiver, new IntentFilter(
CommonUtilities.DISPLAY_MESSAGE_ACTION));
final String regId = GCMRegistrar.getRegistrationId(this);
if (regId.equals("")) {
// Automatically registers application on startup.
GCMRegistrar.register(this, CommonUtilities.SENDER_ID);
} else {
// Device is already registered on GCM, check server.
if (GCMRegistrar.isRegisteredOnServer(this)) {
ServerUtilities.register(mContext, regId);
} else {
// Try to register again, but not in the UI thread.
// It's also necessary to cancel the thread onDestroy(),
// …Run Code Online (Sandbox Code Playgroud) 我再也找不到实现Google Play服务(包括Google Cast,应用内结算等)所需的app_id。
例:
CastOptions castOptions = new CastOptions.Builder()
.setReceiverApplicationId(context.getString(R.string.app_id))
.build();
Run Code Online (Sandbox Code Playgroud)
以前可以通过以下Google Play开发者控制台获取:
但是,Google最近发布了新的Play控制台,并且内容已完全重组:
现在在Play开发者控制台上哪里找到app_id?