javaandroidparse-platformpush-notification

"Pushes sent 0" in parse dashboard for android


I am trying to send push notifications from parse to android. While sending it from browser the calculations of the devices are being shown properly. But "Pushes sent 0" is being displayed in the browser.

I register for notifications in Application class

ParsePush.subscribeInBackground("", new SaveCallback() {
    @Override
    public void done(ParseException e) {
        if (e == null) {
            Log.d("com.parse.push", "successfully subscribed to the broadcast channel.");
        } else {
            Log.e("com.parse.push", "failed to subscribe for push", e);
        }
    }
});
ParseInstallation.getCurrentInstallation().saveInBackground();

I have also created the Receiver in my android project

public class PushMessageBroadcast extends ParsePushBroadcastReceiver {

    @Override
    public void onPushOpen(Context context, Intent intent) {
        Log.d("The push","open");
    }

    @Override
    protected Notification getNotification(Context context, Intent intent) {
        // TODO Auto-generated method stub
        return super.getNotification(context, intent);
    }

    @Override
    protected void onPushDismiss(Context context, Intent intent) {
        // TODO Auto-generated method stub
        super.onPushDismiss(context, intent);
    }

    @Override
    protected void onPushReceive(Context context, Intent intent) {
        //here You can handle push before appearing into status e.g if you want to stop it.
        super.onPushReceive(context, intent);
    }
}

I have also done the changes in manifest:

<receiver
    android:name=".receivers.PushMessageBroadcast "
    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>

Do I need to change any settings in parse? Thanks in advance.


Solution

  • Edited answer

    After @lochana-tejas comment I realized that my answer was not correct because I disabled again in Google Developer console "Cloud Messaging for Android" and my device had received the notification anyway.

    So the first thing you need to control is that in Parse Dashboard you have the class Installation and this class have one or more devices registered. If you don't have this class or is empty “Pushes sent" will be 0.

    enter image description here

    I copy my code here so you can compare

      public static void registerParse(Context context) {
            Parse.setLogLevel(Parse.LOG_LEVEL_VERBOSE);
    
            Parse.initialize(context, PARSE_APPLICATION_ID, PARSE_CLIENT_KEY);
            ParseInstallation.getCurrentInstallation().saveInBackground();
    
            ParsePush.subscribeInBackground(PARSE_CHANNEL, new SaveCallback() {
                @Override
                public void done(ParseException e) {
                    if (e == null) {
                        Log.d("com.parse.push", "Successfully subscribed to Parse!");
                    } else {
                        Log.e("com.parse.push", "failed to subscribe for push", e);
                    }
                }
            });
        }
    
        //This is the user that will be inserted in "Installation class"
        public static void subscribeWithUser(String user) {
            ParseInstallation installation = ParseInstallation.getCurrentInstallation();
    
            installation.put("user", user);
    
            installation.saveInBackground(new SaveCallback() {
                @Override
                public void done(ParseException e) {
                    if (e == null) {
                        Log.e("subscribeWithUser", "User subscribed successfully!!", e);
                    } else {
                        e.printStackTrace();
                        Log.e("subscribeWithUser", "Error to save user", e);
                    }
                }
            });
    
    
        }
    

    My manifest is this

            <!-- Added for Parse push notifications -->
    
            <service android:name="com.parse.PushService" />
            <receiver
                android:name=".receiver.CustomPushReceiver"
                android:exported="false">
                <intent-filter>
                    <action android:name="android.intent.action.BOOT_COMPLETED" />
                    <action android:name="android.intent.action.USER_PRESENT" />
                    <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>
            <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.parse.starter" />
                </intent-filter>
            </receiver>
            <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>