我无法在应用程序中从 Parse 接收推送通知 [英] I can't receive push notifications in app from Parse

查看:27
本文介绍了我无法在应用程序中从 Parse 接收推送通知的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的应用程序中配置了 Parse API,除了推送通知外,一切正常.我试图从网站发送它们,但它们没有到达应用程序.我按照文档中的内容做了所有事情,但我无法接收通知推送.

I configured Parse API in my app and everything works except push notifications. I tried to send them from the site but they don't arrive in app. I did everything as written in documentation, but I'm not able to receive notification pushes.

我能够收到一个,当我按下它时,应用程序崩溃了.现在我试图改变一些东西,但即使逆转我也无法再接收它们.我该如何解决我的问题?

I was able to receive one and when I pressed it app crashed. Now I tried to change something but even with reversing I cannot receive them anymore. How can I resolve my problem?

由于一些用户可能感兴趣,这里是我用于推送通知的代码部分:

Since some users may be interested, here's the parts of the code I used for push notifications:

主类(虽然不是 MainActivity):

Main Class (not MainActivity though):

    public class InstantsApplication extends Application {
public void onCreate() {
    super.onCreate();
    // Hidden
    Parse.initialize(this, "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", 
    "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx");



    ParseInstallation.getCurrentInstallation().saveInBackground();

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

AndroidManifest(这里没有包括权限,相信我已经把它们放好了):

AndroidManifest (permissions not here included, trust me I have put them):

<!-- PARSE -->
<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" />

        <!--
          IMPORTANT: Change "com.parse.tutorials.pushnotifications" to match your app's package name.
        -->
        <!-- I have hidden package name root for this question -->
        <category android:name="com.xxxxxxxx.instants" />


    </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>
</application>

推荐答案

我之前遇到过这个问题,那是因为你使用了最新的 Parse api.您只需要进行一些更改.

I met this problem before, that because you use the newest Parse api. There are just a few changes you need to make.

首先,要修复由 Parse 后端发出推送直接导致的错误,您需要在 Manifest 中为 Parse 推送声明一个通知图标.

First, to fix the error directly caused by issuing the push from the Parse backend you need to declare a notification icon for the Parse push in your Manifest.

 <meta-data android:name="com.parse.push.notification_icon"
            android:resource="@drawable/ic_launcher"/>

在关闭应用程序之前使用-Tag.

use before the closing application-Tag.

现在从后端发出另一个推送将如您预期的那样为您提供推送通知.到现在为止还挺好.单击推送将再次导致应用程序崩溃.要解决此问题,您需要删除现已弃用的调用 PushService.setDefaultPushCallback(...) 并添加您自己的 Receiver 类.我在 *.util 包中这样做了,如下所示:

Issuing another push from the backend now will give you a push notification as you expect. So far so good. Clicking the push will result in an app crash again. To fix this you need to remove the now deprecated call PushService.setDefaultPushCallback(...) and add your own Receiver class. I did this in the *.util package just as the following:

public class Receiver extends ParsePushBroadcastReceiver {

    @Override
    public void onPushOpen(Context context, Intent intent) {
        Intent i = new Intent(context, MainActivity.class);
        i.putExtras(intent.getExtras());
        i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        context.startActivity(i);
    }
}

接下来,将默认的 Parse 接收器更改为刚刚创建的接收器: - 转到您的清单文件.

Next, change the default Parse receiver to the one just created: - Go to your Manifest file.

 <receiver
            android:name="your.package.name.utils.Receiver"
            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>

这篇关于我无法在应用程序中从 Parse 接收推送通知的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆