C2DMReg-HandlerRequest捕获java.net.UnknownHostException:android.clients.google.com

C2DMReg-HandlerRequest捕获java.net.UnknownHostException:android.clients.google.com,android,android-c2dm,google-cloud-messaging,unknown-host,Android,Android C2dm,Google Cloud Messaging,Unknown Host,我的问题与java.net.unknownhosteption:android.clients.google.com[C2DMReg]handleRequest捕获的java.net.unknownhosteption有关。我发现一些被标记为重复的。但所提到的重复与这里所关注的问题无关。这与新的GCM有关,而不是C2DM 我的代码源是 我向GCM注册设备的功能如下: public void register_device(Context c){ Intent registrationI

我的问题与java.net.unknownhosteption:android.clients.google.com[C2DMReg]handleRequest捕获的java.net.unknownhosteption有关。我发现一些被标记为重复的。但所提到的重复与这里所关注的问题无关。这与新的GCM有关,而不是C2DM

我的代码源是


我向GCM注册设备的功能如下:

public void register_device(Context c){
    Intent registrationIntent = new Intent("com.google.android.c2dm.intent.REGISTER");
    registrationIntent.putExtra("app", PendingIntent.getBroadcast(c, 0, new Intent(), 0));
    registrationIntent.putExtra("sender", c.getResources().getString(R.string.SERVER_API_KEY));
    Log.i("GCM", "Starting service for registration Intent");
}
public class MyBroadcastReceiver extends BroadcastReceiver {
    public final void onReceive(Context context, Intent intent) {
        Log.i("GCM", "Received broadcast from Intent: " + intent);
        MyIntentService.runIntentInService(context, intent);
        setResult(MainActivity.RESULT_OK, null, null);
    }
}
我的BroadCastReceiver类如下:

public void register_device(Context c){
    Intent registrationIntent = new Intent("com.google.android.c2dm.intent.REGISTER");
    registrationIntent.putExtra("app", PendingIntent.getBroadcast(c, 0, new Intent(), 0));
    registrationIntent.putExtra("sender", c.getResources().getString(R.string.SERVER_API_KEY));
    Log.i("GCM", "Starting service for registration Intent");
}
public class MyBroadcastReceiver extends BroadcastReceiver {
    public final void onReceive(Context context, Intent intent) {
        Log.i("GCM", "Received broadcast from Intent: " + intent);
        MyIntentService.runIntentInService(context, intent);
        setResult(MainActivity.RESULT_OK, null, null);
    }
}
我的清单文件包含MyBroadcastReceiver的权限,如下所示

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<permission
    android:name="com.mangoesmobile.praxis.pusher.permission.C2D_MESSAGE"
    android:protectionLevel="signature" />
<uses-permission android:name="com.mangoesmobile.praxis.pusher.permission.C2D_MESSAGE" />

<application>
    <receiver
        android:name=".MyBroadcastReceiver"
        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="com.mangoesmobile.praxis.pusher" />
        </intent-filter>
    </receiver>
</application>

日志显示来自register_device function()的我的自定义日志
为注册目的启动服务

然后显示
[C2DMReg]handleRequest捕获的java.net.UnknownHostException:android.clients.google.com
带标签
C2DMRegistrator

它从不显示我的自定义日志
从Intent接收的广播
从MyBroadcastReceiver接收的广播。所以我相信它永远不会到达我的收信人那里。我无法理解为什么会发生这种情况


我没有使用模拟器。我正在使用我自己的设备,并且它已在谷歌帐户中注册。

试一试如何?看起来你的设备存在一些连接问题-android.clients.google.com-应该可以访问-试一试adb shell ping android.clients.google.com有时我很遗憾自己是一名软件工程师。。。。。。。。。在过去的几个小时里,我忘记打开设备的Wifi。非常抱歉。