简体   繁体   English

无法在Android上接收解析推送通知

[英]Cannot receive Parse push notifications on Android

I am developing simple android app and very new to parse. 我正在开发简单的android应用程序,并且非常新来解析。 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. 解析CORE是一个简单的部分,但是我无法从android设备发送推送通知。 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!! 在“安装”类中添加行,并且GCMSenderId为空! Is this the issue? 这是问题吗? Please help me out why I can't receive notifications when sent from my android device? 请帮帮我,为什么我从Android设备发送时无法收到通知? Libs used: Bolts-android-1.1.4.jar Parse-1.8.2.jar ParseCrashReporting-1.8.2.jar 使用的库:Bolts-android-1.1.4.jar Parse-1.8.2.jar ParseCrashReporting-1.8.2.jar

If you have just created the App in Parse and integrated in your App, It generally not works immediately Same thing happened to me. 如果您刚刚在Parse中创建了应用程序并将其集成到您的应用程序中,那么它通常不会立即起作用。 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. 大约需要20分钟。 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 您可以尝试查看Parse Analytics(分析)。(如果已实现) Parse在Analytics(分析)仪表板中显示“请求”,则它将完全正常运行

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM