parse-server: Android doesn't receive push notifications from Parse Server

Hi! Since I didn’t have success asking this in Stackoverflow I’m trying this way.

I’ve migrated my Android and iOS apps from parse.com to Parse Server. After the migration, everything is working well but the push notifications to Android devices (they are working well to my iOS app).

This is what I’ve done so far.

1. In my Parse Server code (on Digital Ocean by the way), in /home/parse/index.js I’ve initialized Parse Server this way:

var api = new ParseServer({  
  databaseURI: databaseUri || '<my mongodb url>',
  cloud: process.env.CLOUD_CODE_MAIN || __dirname + '/cloud/main.js',
  appId: process.env.APP_ID || '<my app ID>',
  masterKey: process.env.MASTER_KEY || '<my master Key>',
  serverURL: process.env.SERVER_URL || 'http://localhost:1337/parse',
  push: {
    android: {
        senderId: '<my GCM sender Id>',
        apiKey: '<my GCM API Key>'
      },
    ios: [{
      pfx: '/home/parse/<my dev P12>',  
      passphrase: '',
      cert: '',
      key: '',
      bundleId: '<my bundle ID>',
      production: false
    },
    {
      pfx: '/home/parse/<my prod P12>',  
      passphrase: '',
      cert: '',
      key: '',
      bundleId: '<my bundle ID>',
      production: true
    }]
  }
});

I’ve taken “my GCM sender ID” from my Google Developer Consoler, it’s the 12 digits number from Settings > Project number.

I’ve tried with 3 different “my GCM API Key”, one without app restrictions, one available only for my android/debug.keystore and one available only for my app keystore.

I’ve checked that I have selected this app in my Google Developer console and that my package id is correct in all places.

2. In Android I’m initializing Parse this way:

public static void initParse(Application app) {
    ctxt = app.getApplicationContext();
    Parse.initialize(new Parse.Configuration.Builder(ctxt)
            .applicationId("<my app id>")
            .clientKey(null)
            .server("https://<my new server>/parse/")
            .enableLocalDataStore()
            .build()
    );
    ParseUser.enableRevocableSessionInBackground();
    ParseInstallation.getCurrentInstallation().saveInBackground();
}

3. In Android I’ve added this to my Android Manifest:

<meta-data android:name="com.parse.push.gcm_sender_id"
                   android:value="id:<my GCM sender Id>" />;

The rest of my manifest and my GCM configuration is the same I had before the migration.

4. Setting the GCMSenderId.

Some comments in Stackoverflow pointed that this could be an issue with GCMSenderId. Indeed all my Android users in Parse Server has an undefined GCMSenderId. But if I set manually this value to <my GCM sender Id> or even id<my GCM sender Id>the push notification is not sent.

5. And as a summary.

With old parse.com push notifications worked well with Android and iOS.

With new Parse Server and the code described above iOS push notifications are working well.

With new Parse Server and the code described above Android push notifications are not being received.

With my new Parse Dashboard installed in Digital Ocean when sending push notifications both to iOS and to Android Dashboard gives a Saved! what makes me thing it’s a problem with my Android app and not with my Parse Dashboard/Parse Server configuration.

What am I missing here?

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Comments: 55 (8 by maintainers)

Most upvoted comments

FYI – if you are using Gradle you can use {packageName} as mentioned in http://guides.codepath.com/android/Push-Notifications-Setup-for-Parse#add-push-permissions so you don’t have to worry about the app name misconfig.

This is my Android manifest:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
          package="com.sample.package" >

    <uses-permission android:name="android.permission.INTERNET" />
    <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />
    <user-permission android:name="android.permission.ACCESS_WIFI_STATE" />
    <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.BLUETOOTH" />
    <uses-permission android:name="com.android.vending.BILLING" />

    <!-- FOR PUSH NOTIFICATIONS -->
    <!--<uses-permission android:name="android.permission.INTERNET" />-->
    <!--<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE" />-->
    <uses-permission android:name="android.permission.WAKE_LOCK" />
    <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
    <uses-permission android:name="android.permission.VIBRATE" />
    <!--<uses-permission android:name="android.permission.GET_ACCOUNTS" />-->
    <uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />

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

    <application
        android:allowBackup="true"
        android:icon="@drawable/launch_ico_1024"
        android:label="@string/app_name"
        android:theme="@style/AppTheme">

        <!-- ACTIVITIES ARE NOT SHOWN --> 

        <!-- FOR PUSH NOTIFICATIONS -->
        <service android:name="com.parse.PushService" />


        <service
            android:name=".services.MyFirebaseInstanceIDService" >
            <intent-filter>
                <action android:name="com.google.firebase.INSTANCE_ID_EVENT" />
            </intent-filter>
        </service>
        <service
            android:name=".services.MyFirebaseMessagingService">
            <intent-filter>
                <action android:name="com.google.firebase.MESSAGING_EVENT" />
            </intent-filter>
        </service>
        <receiver android:name="com.parse.ParseBroadcastReceiver">
            <intent-filter>
                <action android:name="android.intent.action.BOOT_COMPLETED" />
                <action android:name="android.intent.action.USER_PRESENT" />
            </intent-filter>
        </receiver>
        <receiver android:name="com.parse.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.sample.package" />
            </intent-filter>
        </receiver>
        <receiver android:name="com.parse.ParsePushBroadcastReceiver" android:exported="false">
            <intent-filter>
                <action android:name="com.parse.push.intent.RECEIVE" />
                <action android:name="com.parse.push.intent.DELETE" />
                <action android:name="com.parse.push.intent.OPEN" />
            </intent-filter>
        </receiver>

        <meta-data android:name="com.parse.push.gcm_sender_id"
                   android:value="id:XXXXX" />;
    </application>

</manifest>