且构网

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

我无法从解析收到推送通知的应用程序

更新时间:2022-10-26 21:24:21

我遇到过这个问题,是因为你使用最新的解析API。 你需要有只是有一些变化。

首先,要解决造成直接发出的解析后端需要声明一个通知图标的解析推你的清单推的错误。

 <元数据的android:NAME =com.parse.push.notification_icon
            机器人:资源=@可绘制/ ic_launcher/>
 

收盘应用标签之前使用。

如您所愿发出从后端的另一个推现在给你一个推送通知。到目前为止,一切都很好。点击推会导致应用程序崩溃了。为了解决这个问题,你需要删除现在去precated呼叫 PushService.setDefaultPushCallback(...)并添加自己的接收器类。我在* .util包做只是为以下内容:

 公共类接收器扩展ParsePushBroadcastReceiver {

    @覆盖
    公共无效onPushOpen(上下文的背景下,意图意图){
        意图I =新的意图(背景下,MainActivity.class);
        i.putExtras(intent.getExtras());
        i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        context.startActivity(ⅰ);
    }
}
 

接下来,默认解析接收器切换到刚才创建的: - 转到您的清单文件

 <接收器
            机器人:名称=your.package.name.utils.Receiver
            机器人:出口=假>
            <意向滤光器>
                <作用机器人:名称=com.parse.push.intent.RECEIVE/>
                <作用机器人:名称=com.parse.push.intent.DELETE/>
                <作用机器人:名称=com.parse.push.intent.OPEN/>
            &所述; /意图滤光器>
        < /接收器>
 

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?

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

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 (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>

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

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

use before the closing application-Tag.

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

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>