且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

我无法在应用程序中从 Parse 接收推送通知

更新时间:2021-09-05 02:44:08

我之前遇到过这个问题,那是因为你使用了最新的 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>