Can't send push from Parse.com

眉间皱痕 提交于 2019-12-02 08:54:25

I had a similar issue that was resolved in a strange way, but still - might help:

if you re-install (actually re-deploy, sometimes uninstalling sometimes just running over an existing apk) your application on a device, it might create several entries for device tokens that point to the same actual device (inside the Parse dashboard, go to Core, you can see the full table there), in which case - the system doesn't always know which is the correct physical device.

this might explain:

a. the dashboard telling you it will send more than 1 message (assuming only 1 was supposed to be sent).

b. your friend getting the push (he has only 1 valid device token)

Anyway - the refresh button on the Core page didn't help, but - manualy sending a push from the dashboard would result in the device receiving multiple pushes (for the number of duplicates it had in the table), and then, re-entering the Core table page would automatically clear the duplicates. from there on - Pushes got back to normal. you might need another clean, complete removal and re-installation on the device.

Hope this Helps!

Note: GCM Credentials were'nt needed in my case.

The main problem is I was working with Genymotion.

Being a simulator, push notifications should ARRIVE or NOT ARRIVE at all, but they were arriving sometimes. I can't explain why.

In your parseApplication class declare the channel. If you are sending notifications you have to set the channel. See this ParsePush.subscribeInBackground . It is describing the channel .

public class ParseApplication extends Application {

@Override
public void onCreate() {
    super.onCreate();
    System.out.println("Application");
    Parse.initialize(this, "86q5mwgypd1Q2URFV6kJh5MBPmUpuPvoN3lTdeWx", "OhrkrJTuTwtbMprYtiywnQ3f4wnQdr5pitmI7tNt");

    ParsePush.subscribeInBackground("temboo", 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);
                Toast.makeText(ParseApplication.this, "Failed to subscribe for push.", Toast.LENGTH_SHORT).show();
            }
        }
    });

This works for me.

  Parse.enableLocalDatastore(this);

    // Add your initialization code here
    Parse.initialize(this, APP_ID, CL_ID);
    ParseInstallation.getCurrentInstallation().saveInBackground();

    ParseUser.enableAutomaticUser();
    ParseACL defaultACL = new ParseACL();
    // Optionally enable public read access.
    // defaultACL.setPublicReadAccess(true);
    ParseACL.setDefaultACL(defaultACL, true);



    // IF NEEADED
    String topic ="YOUR_TOPIC";
    System.out.println(topic);
    ParsePush.subscribeInBackground(topic, new SaveCallback() {
        @Override
        public void done(ParseException e) {
            if (e == null) {
                Log.d("com.parse.push",
                        "successfully subscribed ");
            } else {
                Log.e("com.parse.push", "failed ", e);
            }
        }
    });
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!