sajith
sajith

Reputation: 2702

GCM not delivering to by broadcast receiver

I have successfully send GCM message from server side using my application id and a browser key ,but it is not receiving in my broadcast receiver,I found that it is received by my device but showing some error in Log-cat. Where is my mistake? and what will be the solution for this problem?

<uses-sdk
    android:minSdkVersion="8"
    android:targetSdkVersion="10" />

<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.VIBRATE" />
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<uses-permission android:name="android.permission.GET_ACCOUNTS" />
<uses-permission android:name="android.permission.WAKE_LOCK" />
<uses-permission android:name="in.myapp.tab.C2D_MESSAGE" />

<permission
    android:name="in.myapp.tab.permission.C2D_MESSAGE"
    android:protectionLevel="signature" />

<application
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/Theme.Example" >
    <activity
        android:name="in.myapp.tab.MainActivity"
        android:configChanges="orientation"
        android:label="@string/app_name"
        android:screenOrientation="portrait" >
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />

            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
    </activity>
    <activity android:name="in.myapp.tab.SecondPage" >
    </activity>


    <receiver
        android:name="in.myapp.tab.PullReqReceiver"
        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" /> -->
            <!-- <action android:name="android.net.conn.CONNECTIVITY_CHANGE" /> -->
            <!-- <action android:name="android.net.wifi.WIFI_STATE_CHANGED" /> -->
        </intent-filter>
    </receiver>

    <service android:name=".WebService" />

    <activity
        android:name="com.facebook.LoginActivity"
        android:configChanges="orientation|screenSize|keyboardHidden" />
    <activity
        android:name="in.myapp.tab.LoginActivity"
        android:configChanges="orientation|screenSize|keyboardHidden" >
        <meta-data
            android:name="com.facebook.sdk.ApplicationId"
            android:value="@string/app_id" />
    </activity>

    <meta-data
        android:name="com.facebook.sdk.ApplicationId"
        android:value="@string/app_id" />
</application>

Logcat out is

09-17 18:04:31.329: W/GTalkService(1748): <!>com.google.android.gsf.gtalkservice.DataMessageManager$BroadcastDoneReceiver 100<!> [DataMsgMgr] broadcast intent callback: result=CANCELLED forIntent { act=com.google.android.c2dm.intent.RECEIVE cat=[in.myapp.tab] (has extras) }
09-17 18:04:31.329: W/GTalkService(1748): <!>com.google.android.gsf.gtalkservice.DataMessageManager 334<!> Receiver package not found, unregister application in.myapp.tab sender 
09-17 18:04:31.379: W/GCM(1748): <!>com.google.android.gms.gcm.GcmProvisioning 182<!> DIR: /data/data/com.google.android.gms/app_APP /data/data/com.google.android.gsf
09-17 18:04:33.669: D/GCM(1748): <!>bek 940<!> [C2DMRegistrar.159] Send register result  null 0 0

my server side code is in PHP

 <?php

// Replace with real BROWSER API key from Google APIs
$apiKey = "My BROWSER API key";
$message = "x";
// Set POST variables
$url = 'https://android.googleapis.com/gcm/send';
$headers = array(
'Authorization: key=' . $apiKey,
'Content-Type: application/json'
);

$registrationIDs = array();   
array_push($registrationIDs, $_GET['id']);
  $fields = array(
    'registration_ids' => $registrationIDs,
    'data' => array("message" => $message),
);
   $ch = curl_init();

// Set the url, number of POST vars, POST data
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);

curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($fields));
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, 0);

// Execute post
$result = curl_exec($ch);
echo 'Curl error: ' . curl_error($ch);
// Close connection
curl_close($ch);
echo  $result;

?>>

Upvotes: 1

Views: 1281

Answers (1)

Newts
Newts

Reputation: 1372

I think you missed this intent filter while entry the receiver.

    <action android:name="com.google.android.c2dm.intent.REGISTRATION" />

            <category android:name="in.myapp.tab" />

and also please check your sender id and GCM key for this.

Upvotes: 2

Related Questions