"Pushes sent 0" in android parser
I am trying to send push notifications from parse in android. When sent from a browser, device calculations are displayed correctly. But the browser displays "Pushes sent 0".
I am registering 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 also created 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 also made changes to the 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 the parsing? Thanks in advance.
source to share
Edited answer
After @ lochana-tejas comment, I realized that my answer was wrong because I got disconnected again in Google Developer Console "Cloud Messaging for Android" and my device still got a notification.
So the first thing you need to control is that in the Parse Dashboard you have an Installation class , and that class has one or more registered devices. If you don't have this class or is empty, then "Pushes sent" will be 0.
I am copying 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 manifestation is
<!-- 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>
source to share