My question is related to [C2DMReg] handleRequest caught java.net.UnknownHostException: android.clients.google.com I found some question in StackOverflow with the same title that has been marked as duplicate. But the duplicate that is mentioned has nothing to do with the matter at concern here. This is related to the new GCM - not C2DM.
My code sources are from the GCM tutorial in Android API Guide
My function for registering the device with GCM is as follows:
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");
}
My BroadCastReceiver class is as follows:
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);
}
}
My Manifest file contains the permissions for MyBroadcastReceiver as follows
<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>
The logs show my custom log from the register_device function() Starting service for registration Intent
and then shows [C2DMReg] handleRequest caught java.net.UnknownHostException: android.clients.google.com
with tag C2DMRegistrar
It never shows my custom log Received broadcast from Intent
from MyBroadcastReceiver. So it never reaches MyBroadcastReceiver i believe. I am not able to figure why would this happen.
I am not using an emulator. I am using my own device and it is registered with a google account.