0

when I try to send message (from server to mobile using GCM push notification) I am getting following error. I have tried the all the solutions that have given in other posts in stackoverflow

{"multicast_id":xxxxxx,"success":0,"failure":1,"canonical_ids":0,"results":[{"error":"MismatchSenderId"}]}

  1. I have done my registration in GCM

    Server key 1: xxxxxxxxxx Project ID: xxxxxx

  2. In my android code I have set following (my package name is com.revu.revu)

    a. Manifest file:

        // When notification received from GCM, then activate this service
        <service
            android:name=".PushNotificationService"
            android:exported="false">
            <intent-filter>
                <action android:name="com.google.android.c2dm.intent.RECEIVE" />
            </intent-filter>
        </service>

        <receiver
            android:name="com.google.android.gms.gcm.GcmReceiver"
            android:exported="true"
            android:permission="com.google.android.c2dm.permission.SEND">
            <intent-filter>
                <action android:name="com.google.android.c2dm.intent.RECEIVE" />
                <category android:name="com.revu.revu" />
            </intent-filter>
        </receiver>

<uses-permission android:name="android.permission.RECEIVE_SMS" />
<uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
<permission android:name="com.revu.revu.permission.C2D_MESSAGE"
    android:protectionLevel="signature" />
<uses-permission android:name="android.permission.READ_SMS" />
<uses-permission android:name="com.revu.revu.permission.C2D_MESSAGE" />

b. I have got the registration ID from GCM server and I stored in my server.

c. When I try to send message to registration id with the API key (server key), I am getting above error (mismatchsenderId).

I have used following php code to send message

<?php
// API access key from Google API's Console
define( 'API_ACCESS_KEY', 'xxxxxxxxxxxxxxxxx');
$regId = "APA91bFidqJmnqm0GGmWRmkwB8Kn4fLJ0WPUTbWo3l2bbgQGNnzqbiYKyB4QJ-_JlvoA2tHFhgON2egA_1eJ82TA2sm38qdJVeP2Qk4CW1poxMcFu0emUC1Y_Lf3otKy6U5YAnn2ralS"; 
$registrationIds = array($regId);
// prep the bundle
$msg = array
(
 'message'  => 'here is a message. message',
 'title'  => 'This is a title. title',
 'subtitle' => 'This is a subtitle. subtitle',
 'tickerText' => 'Ticker text here...Ticker text here...Ticker text here',
 'vibrate' => 1,
 'sound'  => 1,
 'largeIcon' => 'large_icon',
 'smallIcon' => 'small_icon'
);
$fields = array
(
 'registration_ids'  => $registrationIds,
 'data'   => $msg
);
 
$headers = array
(
 'Authorization: key=' . API_ACCESS_KEY,
 'Content-Type: application/json'
);
 
$ch = curl_init();
curl_setopt( $ch,CURLOPT_URL, 'https://android.googleapis.com/gcm/send' );
curl_setopt( $ch,CURLOPT_POST, true );
curl_setopt( $ch,CURLOPT_HTTPHEADER, $headers );
curl_setopt( $ch,CURLOPT_RETURNTRANSFER, true );
curl_setopt( $ch,CURLOPT_SSL_VERIFYPEER, false );
curl_setopt( $ch,CURLOPT_POSTFIELDS, json_encode( $fields ) );
$result = curl_exec($ch );
curl_close( $ch );
echo $result;

?>

Please help me, am I missing any step here.

  • it meant your senderid is wrong, check it again plz – Bui Quang Huy Apr 10 '16 at 19:51
  • Please suggest me some links which gives the complete procedure for app registration in GCM – Masthan Vali Syed Apr 11 '16 at 11:01
  • I follow this one and success: http://www.androidwarriors.com/2015/10/push-notification-using-gcm-in-android.html – Bui Quang Huy Apr 11 '16 at 16:18
  • Thankq, I will try this – Masthan Vali Syed Apr 12 '16 at 06:49
  • Is it mandatory to place the app in **Google Play Store** ? to get the GCM Push notification working?. Till now I am creating apk file and directly installing it in my mobile and trying... – Masthan Vali Syed Apr 12 '16 at 18:01
  • No need to push your app in google play store, it just require Google Play Service for your emulator – Bui Quang Huy Apr 13 '16 at 01:10
  • Bui, I have followed above link that you have given. I am using Project/sender ID and its APK ID in Android Project and PHP file respectively. Once app is registered with GCM server and again if I want to register, **is it mandatory to unregistered existing one from GCM server?**. Also I have created multiple projects just to check and now I am using only one project, I am using this project related Project ID and API Key. **The multiple project creation causing any problem?** – Masthan Vali Syed Apr 13 '16 at 05:21
  • I have resolved the issue. The above shown error will be displayed even if registration ID is incorrect. – Masthan Vali Syed Apr 14 '16 at 04:55

1 Answers1

0

I think it has something to do with the way you have set up API access for your project in the Google Developer Console,

Mismatched Sender ID is tied to a certain group of senders. when an application registers for GCM usage, it must specify which senders are allowed to send messages. Make sure you're using one of those when trying to send messages to the device. If you switch to a different sender, the registration IDs don't work. Happens when error code is 'MismatchSenderId'.

Here is a related SO ticket which discuss MismatchSenderID: PHP GCM error message MismatchSenderId

Community
  • 1
  • 1
Android Enthusiast
  • 4,826
  • 2
  • 15
  • 30
  • Please suggest me some links which gives the complete procedure for app registration in GCM – Masthan Vali Syed Apr 11 '16 at 11:05
  • Is it mandatory to place the app in Google Play Store ? to get the GCM Push notification working?. Till now I am creating apk file and directly installing it in my mobile and trying.. – Masthan Vali Syed Apr 12 '16 at 18:02