So I've been having an issue for the past 15 hours or so, I followed GCM's getting started for Android (client demo source included) and as far as I know, I'm supposed to receive a push notification soon after registering the device and after sending an ECHO_NOW message. Here's what I've done and some code snippets:
I have been running the code in an HTC One (4.3)
- Followed the official documentation thoroughly and created the app making use of the Google Play Services lib (froyo package)
- I created and declared a main
Activity
, anIntentService
, and aWakefulBroadcastReceiver
-extended receiver. - I made sure to check the GCM Console, I have the right Sender ID, Enabled push notif to Android devices, and fingerprint from the debug keystore, along with the app package.
- I added right permissions and also made sure I had the right package across the permissions and required Intent actions.
AndroidManifest.xml:
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="my.package"
android:versionCode="1"
android:versionName="1.0" >
<uses-sdk
android:minSdkVersion="8"
android:targetSdkVersion="19" />
<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="my.package.permission.C2D_MESSAGE"
android:protectionLevel="signature" />
<uses-permission android:name="my.package.permission.C2D_MESSAGE" />
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="@string/app_name"
android:theme="@style/AppTheme" >
<activity
android:name="my.package.MainActivity"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<receiver
android:name="my.package.GcmBroadcastReceiver"
android:permission="com.google.android.c2dm.permission.SEND" >
<intent-filter>
<action android:name="com.google.android.c2dm.intent.RECEIVE" />
<category android:name="my.package" />
</intent-filter>
</receiver>
<service android:name="my.package.GcmIntentService" />
</application>
</manifest>
I made an assumption that I would receive a push notification after reading this (included in the source code for the gcm client demo implementation):
// For this demo: we don't need to send it because the device
// will send upstream messages to a server that echo back the
// message using the 'from' address in the message.
Ever since the first try, the devices is being successful in registering and obtaining the registration id.
Question
Did I make the wrong assumption and no push notification should be received? If not, what could be wrong?
I've documented as much as possible, should I post more code? I've checked so many questions and none has tackled this exact problem or just won't fix it.
Thanks in advance to the community.
Sincerely,
Armando
EDIT: Conclusion: GCM Demo Client works perfectly, just need to keep in mind that a server end is needed to request GCM to send the actual push notification. ECHO_NOW does not mean that something will be sent by GCM in your behalf. Implement the server side!
Marked answer (Eran's) was the first one, BUT Rajat's provides snippet for whoever needs a heads up. Thank you both.