Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/211.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android Google云消息注册方法因IOException(主线程)失败_Android_Google Cloud Messaging - Fatal编程技术网

Android Google云消息注册方法因IOException(主线程)失败

Android Google云消息注册方法因IOException(主线程)失败,android,google-cloud-messaging,Android,Google Cloud Messaging,严格遵循,但仍然出现令人沮丧的错误。我在这里没有找到答案,所以我想我会把它记录下来以备将来参考 我相当确信我已经用正确的权限等正确地设置了清单(完全按照上面的例子)。。。但这段代码总是导致IOException,解释为“MAIN_THREAD” 我试图通过单步执行来发现问题,所以当然在主线程上执行了这段代码。回想起来,答案是显而易见的。。。但我会在下面输入它。鼓点滚动。。。不能在主线程上调用register方法。回想起来很明显,但也许还有其他人和我一样糟糕(但每天更少!)在AsyncTask(d

严格遵循,但仍然出现令人沮丧的错误。我在这里没有找到答案,所以我想我会把它记录下来以备将来参考

我相当确信我已经用正确的权限等正确地设置了清单(完全按照上面的例子)。。。但这段代码总是导致IOException,解释为“MAIN_THREAD”


我试图通过单步执行来发现问题,所以当然在主线程上执行了这段代码。回想起来,答案是显而易见的。。。但我会在下面输入它。

鼓点滚动。。。不能在主线程上调用register方法。回想起来很明显,但也许还有其他人和我一样糟糕(但每天更少!)

在AsyncTask(doInBackGround)

gcm.register(发送方ID)中调用register方法;在doInBackground中,但仍无法注册应用程序并引发IOException
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);
}