谷歌云信息登记方法失败,IOException异常(MAIN_THREAD) [英] Google Cloud Messaging register method fails with IOException (MAIN_THREAD)

查看:167
本文介绍了谷歌云信息登记方法失败,IOException异常(MAIN_THREAD)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

其次谷歌的GCM例如的非常认真,但还是想出了令人沮丧的错误。没有找到答案在这里,所以想我将其记录下来以备将来参考。

Followed Google's GCM example extremely carefully, but still came up with frustrating errors. Didn't find the answer here, so thought I'd document it for future reference.

我相当肯定,我有清单正确设置了正确的权限等(以下上面的例子信)...但是这code总是导致一个IOException,使用说明MAIN_THREAD。

I was fairly sure that I had the manifest properly set up with the correct permissions etc (following the above example to the letter)... but this code always caused an IOException with the explanation "MAIN_THREAD".

String regid = "";
try {
    GoogleCloudMessaging gcm = GoogleCloudMessaging.getInstance(getApplicationContext());
    String sender_id = getResources().getString(R.string.GCM_sender_id);
    regid = gcm.register(sender_id);
    Log.d(TAG, "Device registered, registration id=" + regid);
} 
catch (IOException ex) {
    Log.e(TAG, "Device registration failed", ex);
}

我试图通过加强发现问题,所以当然执行该code中的主线上。现在回想起来,答案是显而易见的......但我会在下面输入。

I was trying to find the problem by stepping through, so of course executed this code on the main thread. In retrospect the answer is obvious... but I'll enter it below.

推荐答案

辊筒式...你不能叫主线程上的注册方法。明显回想起来,但也许还有其他人吸,就像我这样做(但不太每一天!)

Drum roll... you can't call the register method on the main thread. Obvious in retrospect, but perhaps there are others that suck as much as I do (but less each day!)

这篇关于谷歌云信息登记方法失败,IOException异常(MAIN_THREAD)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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