以下是我的代码段
protected String doInBackground(Void... params) {
if(GooglePlayServicesUtil.isGooglePlayServicesAvailable(context) == ConnectionResult.SUCCESS){
GoogleCloudMessaging gcm_instance = GoogleCloudMessaging.getInstance(context);
String reg_id = null;
int attempts = 0;
while(attempts < 3 && reg_id == null){
try{
reg_id = gcm_instance.register(SENDER_ID);
return reg_id;
} catch (IOException e) {
e.printStackTrace();
}
attempts++;
}
}
return null;
}
register方法返回NULL,我得到的异常是SERVICE_NOT_AVAILABLE。我已经交叉检查了发件人ID,并且互联网连接在我的设备上运行正常。
请帮忙。
答案 0 :(得分:0)
我遇到了同样的麻烦。解决方案是使用辅助库,如此链接中所述:http://developer.android.com/google/gcm/helper.html#android-app
为了记录,我使用的设备运行的是Android 4.0.3。 我确实在设备上设置了有效的Google帐户(最终)。
现在我可以注册了。 下一步:看看我是否可以实际推送消息:D
祝你好运。