Cannot receive Parse push notifications on Android

2019-08-07 00:43发布

问题:

I am developing simple android app and very new to parse. I followed parse documentation in adding back-end functionalities. Parse CORE was an easy part but I can’t send push notifications from android device. But push-notifications are received when sent from parse dashboard. My Manifest file is as below:

    <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.VIBRATE" />
        <uses-permission android:name="android.permission.RECEIVE_BOOT_COMPLETED" />
        <uses-permission android:name="android.permission.GET_ACCOUNTS" />
        <uses-permission android:name="com.google.android.c2dm.permission.RECEIVE" />
        <uses-permission android:name="com.google.android.c2dm.permission.SEND" />

        <!--
          IMPORTANT: Change "com.parse.starter.permission.C2D_MESSAGE" in the lines below
          to match your app's package name + ".permission.C2D_MESSAGE".
        -->
        <permission android:protectionLevel="signature"
            android:name="loaniistar.loaniistar.permission.C2D_MESSAGE" />
        <uses-permission android:name="loaniistar.loaniistar.permission.C2D_MESSAGE" />

<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.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>
        <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" />

                <!--
                  IMPORTANT: Change "com.parse.starter" to match your app's package name.
                -->
                <category android:name="loaniistar.loaniistar" />
            </intent-filter>
        </receiver>

Application Class:

public class MApplication extends Application {

    String applicationiId = "5npdddECsGdDk49OttttuHq6iZdZpddI0cHDsz";
    String clientKey = "SjF1BWamssstycthSjf2dddduhcuwW2VccccCCuFlE";

    public UserAccounts userAccount = null;

    @Override
    public void onCreate() {
        super.onCreate();

        Parse.enableLocalDatastore(this);
        ParseCrashReporting.enable(this);
        Parse.initialize(this, applicationiId, clientKey);
        PushService.startServiceIfRequired(this);
    }

}

Subscribing for channel in an activity class:

ParsePush.subscribeInBackground("manager", new SaveCallback() {
                    @Override
                    public void done(ParseException e) {
                        if (e == null) {

                        }
                        else
                        {
                            btnLoginEnable();
                        }
                    }
                });

Sending Push Notification in another activity class:

 // Sending Push
                    ParsePush push = new ParsePush();
                    push.setChannel("manager");
                    push.setMessage(m.getMessage().substring(0, (int) m.getMessage().length() / 3));
                    //push.sendInBackground();
                    push.sendInBackground(new SendCallback() {
                        @Override
                        public void done(ParseException e) {
                            if(e == null)
                            {
                                Toast.makeText(getActivity(), "Notification sent", Toast.LENGTH_SHORT).show();
                            }
                            else {
                                Toast.makeText(getActivity(), "Notification Not sent", Toast.LENGTH_SHORT).show();
                            }
                        }
                    });

Row is added in “Installation” class and GCMSenderId is empty!! Is this the issue? Please help me out why I can’t receive notifications when sent from my android device? Libs used: Bolts-android-1.1.4.jar Parse-1.8.2.jar ParseCrashReporting-1.8.2.jar

回答1:

If you have just created the App in Parse and integrated in your App, It generally not works immediately Same thing happened to me. I was not getting the data, but after some time I got the requests when I saw the Parse Dashboard

It will take Approx 20 mins. You can try to see the Parse Analytics.(if you have implemented it) if Parse shows Requests in your Analytics Dashboard then It will work completely fine