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

2023-09-12 10:24:40 作者:_____旧情劫′

我在我的应用程序配置解析API和一切工作,除了推送通知。我试图从他们的网站发送,但他们没有在app到达。 我所做的一切写在文档,但我无法收到通知推。

我能接受之一,当我pressed它的应用程序崩溃。现在我想改变一些东西,但即使有倒车,我不能接受他们了。我怎样才能解决我的问题?

编辑:由于一些用户可能会感兴趣,这里的code口用于推送通知的部分:

主类(不MainActivity虽然):

 公共类InstantsApplication扩展应用{
公共无效的onCreate(){
    super.onCreate();
    // 隐
    Parse.initialize(这一点,xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
    xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx);



    。ParseInstallation.getCurrentInstallation()saveInBackground();

    ParsePush.subscribeInBackground(,新SaveCallback(){
        @覆盖
        公共无效完成(ParseException的E){
            如果(E == NULL){
                Log.d(com.parse.push,成功订阅广播频道。);

            } 其他 {
                Log.e(com.parse.push,未能认购推,E);
            }
        }
     }
}
 

AndroidManifest(权限不包括在内,相信我,我已经把他们):

 <! -  PARSE  - >
<服务机器人:名称=com.parse.PushService/>
<接收器的Andr​​oid版本:NAME =com.parse.ParseBroadcastReceiver>
    <意向滤光器>
        <作用机器人:名称=android.intent.action.BOOT_COMPLETED/>
        <作用机器人:名称=android.intent.action.USER_ preSENT/>
    &所述; /意图滤光器>
< /接收器>
<接收器的Andr​​oid版本:NAME =com.parse.GcmBroadcastReceiver
          机器人:权限=com.google.android.c2dm.permission.SEND>
    <意向滤光器>
        <作用机器人:名称=com.google.android.c2dm.intent.RECEIVE/>
        <作用机器人:名称=com.google.android.c2dm.intent.REGISTRATION/>

        <! - 
          重要提示:改变com.parse.tutorials.pushnotifications,以配合您的应用程序包名称。
         - >
        <! - 我已经隐藏包名根这个问题 - >
        <类机器人:名称=com.xxxxxxxx.instants/>


    &所述; /意图滤光器>
< /接收器>
<接收器的Andr​​oid版本:NAME =com.parse.ParsePushBroadcastReceiver机器人:出口=假>
    <意向滤光器>
        <作用机器人:名称=com.parse.push.intent.RECEIVE/>
        <作用机器人:名称=com.parse.push.intent.DELETE/>
        <作用机器人:名称=com.parse.push.intent.OPEN/>
    &所述; /意图滤光器>
< /接收器>
< /用途>
 

解决方案

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

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

 <元数据的android:NAME =com.parse.push.notification_icon
            机器人:资源=@可绘制/ ic_launcher/>
 
在未来2018年有哪些有趣的Web应用程序发展趋势

收盘应用标签之前使用。

如您所愿发出从后端的另一个推现在给你一个推送通知。到目前为止,一切都很好。点击推会导致应用程序崩溃了。为了解决这个问题,你需要删除现在去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>