简体   繁体   English

我无法在Parse的应用程序中收到推送通知

[英]I can't receive push notifications in app from Parse

I configured Parse API in my app and everything works except push notifications. 我在我的应用程序中配置了Parse API,除推送通知外,一切正常。 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): 主类(不是MainActivity):

    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): AndroidManifest(权限不在此处,相信我,我已经把它们):

<!-- 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. 之前我遇到过这个问题,因为你使用的是最新的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. 首先,要修复由Parse后端发出推送直接导致的错误,您需要在Manifest中为Parse推送声明一个通知图标。

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

use before the closing application-Tag. 在关闭应用程序之前使用-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. 要解决此问题,您需要删除现已弃用的调用PushService.setDefaultPushCallback(...)并添加您自己的Receiver类。 I did this in the *.util package just as the following: 我在* .util包中做了这个,如下所示:

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. 接下来,将默认的Parse接收器更改为刚创建的接收器: - 转到Manifest文件。

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

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

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