I was hoping I won't get to this, but I have been busting my head for the past 2 days with something that looks pretty simple. I have already implemented my C2DM application client + server, following the tutorials from google and vogella.
I will try to describe my problem briefly:
So I figure that most probably my problem is with my receiver for the messages, because they are sent from my third party server to the C2DM server, but cannot get from there to my application.
I read on related topics on StackOverflow that the problem might be with the port on the device, but I am currently using the same receiver for both registering the application and receiving messages, and the registration part works every time.
Here is my receiver:
public class C2DRegistrationReceiver extends BroadcastReceiver{
@Override
public void onReceive(Context context, Intent intent) {
String action = intent.getAction();
if (action != null){
if (action.equals("com.google.android.c2dm.intent.REGISTRATION")){
// do something
}
else if (action.equals("com.google.android.c2dm.intent.RECEIVE")){
// do something else
}
}
}
}
My Manifest file:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="ro.raullepsa.coder"
android:versionCode="1"
android:versionName="1.0" >
<!-- SDK min version -->
<uses-sdk android:minSdkVersion="8" />
<!-- Only this application can receive the messages and registration result -->
<permission android:name="ro.raullepsa.coder.permission.C2D_MESSAGE" android:protectionLevel="signature" />
<uses-permission android:name="ro.raullepsa.coder.permission.C2D_MESSAGE" />
<!-- This app has permission to register and receive messages from Google's c2dm -->
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<!-- Permission to use internet -->
<uses-permission android:name="android.permission.INTERNET" />
<application
android:icon="@drawable/ic_launcher"
android:label="@string/app_name" >
<!-- Activities -->
<activity
android:name="ro.raullepsa.coder.activity.MainActivity"
android:label="@string/app_name"
android:exported="true">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity android:name="ro.raullepsa.coder.activity.RegistrationResultActivity" />
<activity android:name="ro.raullepsa.coder.activity.MessageReceivedActivity" />
<receiver
android:name="ro.raullepsa.coder.util.c2d.C2DRegistrationReceiver"
android:permission="com.google.android.c2dm.permission.SEND">
<!-- Receive messages -->
<intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
<category android:name="ro.raullepsa.coder" />
</intent-filter>
<!-- Receive the registration id -->
<intent-filter>
<action android:name="com.google.android.c2dm.intent.REGISTRATION" />
<category android:name="ro.raullepsa.coder" />
</intent-filter>
</receiver>
</application>
</manifest>
I get no errors, I have tried over and over again to reinstall the application, re-register, I have tried with 2 separate receivers, I have manually force-stopped all services running from C2DM and reinstalled, but still nothing.
I've tried in debug mode to wait on the first line of the receiver, and it gets there on registering, but never after I send a message from the server.
I am kind of stuck and would appreciate any help. I can provide more code if needed, although my application is basically Lars Vogel's tutorial. What am I missing?
Well, something interesting happened. Although I didn't make any changes in the code from the previous night, when I woke up this morning and turned on the Wifi I received a message.
Now everything works fine. As soon as I send a message I automatically get in on the device. (and yes, my Wifi was also on last night)
I am not sure what caused the delay, as I was receiving a positive response code from the Google servers but nothing on my device. Probably it took some time to send the first message? I am not sure.
I tried on other Wifi networks and it also works. Hope I won't bump into this anymore. Still, I find the behavior somehow strange.