Question

I successfully implemented the GCM mechanism. I receive all the notifications on Google N5. but when I try the same application on Samsung tabs and other devices such as micromax etc , even though they receive a success response and a registration id for my handset. I do not receive the messages from GCM servers. Could someone please figure out what may be the problem?

This is my manifest file containing all permissions:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.mypackage"
    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="com.mypackage.permission.C2D_MESSAGE"
        android:protectionLevel="signature" />
    <uses-permission android:name="com.mypackage.permission.C2D_MESSAGE" />

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >
        <activity
            android:name="com.mypackage.DemoActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>

         <meta-data android:name="com.google.android.gms.version"
           android:value="@integer/google_play_services_version" />

        <receiver
            android:name=".GcmBroadcastReceiver"
            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.mypackage" />
            </intent-filter>
        </receiver>
        <service android:name=".GcmIntentService"
                 android:enabled="true" />
    </application>

</manifest>

Any changes I need to do in my manifest?

Was it helpful?

Solution

Hope this link may solve your issue. http://captechconsulting.com/blog/antoine-campbell/google-cloud-messaging-cloud-connection-server-tutorial

Permissions Notice that GCM requires that the application define a new permission for use, com.antoinecampbell.gcmdemo.permission.C2D_MESSAGE. This permission prevents other applications from receiving the GCM message for your application.

<uses-permission android:name="android.permission.GET_ACCOUNTS"/>
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.USE_CREDENTIALS"/>
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE"/>
<uses-permission android:name="android.permission.WAKE_LOCK"/>

<permission 
    android:name="com.antoinecampbell.gcmdemo.permission.C2D_MESSAGE" 
    android:protectionLevel="signature"/>
<uses-permission android:name="com.antoinecampbell.gcmdemo.permission.C2D_MESSAGE"/>

Components The SEND permission ensures only the GCM Framework can send messages to the BroadcastReceiver. The IntentService in the demo application does the actual handling of the message it was passed by the BroadcastReceiver.

<receiver 
    android:name=".GcmBroadcastReceiver" 
    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.antoinecampbell.gcmdemo"/>
    </intent-filter>
</receiver>
<service android:name=".GcmIntentService"></service>

Device Registration Before any device can be used with GCM it must first register with the GCM servers. This can be done using the GoogleCloudMessaging class within the Google Play Services library. This is a blocking call so it should be performed in the background using an AsyncTask. A registration ID will be returned that uniquely identifies the device for the ProjectID used. Registration should occur in the onCreate() method of your activity, or using a dialog if you would like to give the user a choice about receiving GCM messages. This is generally something you do only once. The demo shows how to unregister as well, though it is not a common action. The only time you may want to unregister a device is if you allow the user to opt-out of receiving GCM messages within your application.

Once the registration ID is retrieved, it should be sent to your server to be saved in a database and stored locally on the device. The demo application stores the registration ID in SharedPreferences and sends the ID off to the CCS application using a GCM message. It is recommended that this be done via HTTP so you have an immediate answer on its success or failure. The CCS application handles the same functions an HTTP server would by storing the usernames and device registration IDs.

OTHER TIPS

Thanks a lot folks for the help..It was my mistake that I did not recognize earlier..the Wifi on which i was testing was that of my company organization..So it had ports 5228,5229 and 5230 blocked..So I wasnt able to recieve any incoming traffic.It wasn't the issue of the device..It was connectivity issue..Any ways thanks for everybody's help..Got to learn a lot more about GCM than i knew previously..

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top