Can't send push from Parse.com

2019-03-03 18:21发布

问题:

I had a project with Parse in my app, but I've changed the project (and so the keys) and my pushes (test or normal) doesn't get sent from Parse.

When I try to send them I'm notified that it's going to be received by 2 recipients:

My Client push is ENABLED:

Although I think it's not needed, I've got my GCM credentials:

  • I've tried with a custom ParsePushBroadcastReceiver extended on Android and logging onReceive
  • I've tried to sign as release and debug.
  • I've tried with Wi-Fi, 3G and 4G.
  • I've tried to clear data, uninstall the app, rebooting.

My permissions on AndroidManifest.xml are:

<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="taggie.me.permission.C2D_MESSAGE" />
<uses-permission android:name="taggie.me.permission.C2D_MESSAGE" />

My application is:

<application
    android:name=".MainApplication"
    android:allowBackup="true"
    android:icon="@drawable/logo_help"
    android:label="@string/app_name"
    android:theme="@style/AppTheme" >

which code is:

public class MainApplication extends Application {

    @Override
    public void onCreate() {
        super.onCreate();
        Parse.initialize(this, "YBi4ki505TcwKSNEIW7gkFCdWvjHC9yNJmrZHBGR", "APwUw3laazYRhvkSRwZZqpxsROUjH5jWP6QzeHiq");
        ParseInstallation.getCurrentInstallation().saveInBackground();
    }
}

and the rest of my AndroidManifest.xml is:

    <service android:name="com.parse.PushService" />
    <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="taggie.me" />
        </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:10321_and_the_rest_of_my_number" />; 

but THE PROBLEM IS HERE

I don't get notifications, and when I send them I can see this:

Does anyone has a clue before shooting myself? Thank you :)


This is incredible, I've tried to send the apk to one friend of mine... and he gets the push notifications but I don't! why could it be possible?


I've just opened the port 8253 as I've seen some posts reporting this, but it's still not working. :'(

回答1:

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.



回答2:

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.



回答3:

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();
            }
        }
    });


回答4:

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);
            }
        }
    });