ICode9

精准搜索请尝试: 精确搜索
首页 > 编程语言> 文章详细

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

2019-10-28 23:27:27  阅读:271  来源: 互联网

标签:parse-platform push-notification java android


我在应用程序中配置了Parse API,除推送通知外,其他所有功能均正常.我试图从网站发送它们,但它们没有到达应用程序.
我已按照documentation的要求进行了所有操作,但无法收到通知推送.

我能够收到一个,当我按它时,应用程序崩溃了.现在,我尝试更改某些内容,但即使反转,也无法再接收它们.我该如何解决我的问题?

编辑:由于某些用户可能感兴趣,所以这是我用于推送通知的部分代码:

主类(虽然不是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(权限不包括在这里,相信我,我已经把它们放了):

<!-- 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.
您只需要进行一些更改.

首先,要修复直接从Parse后端发出推送而导致的错误,您需要在清单中声明解析推送的通知图标.

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

在结束前使用application-Tag.

现在,从后端发出另一个推送将按您的预期发送推送通知.到现在为止还挺好.单击该推送将再次导致应用程序崩溃.要解决此问题,您需要删除现已弃用的调用PushService.setDefaultPushCallback(…),并添加自己的Receiver类.我在* .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);
    }
}

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

 <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-platform,push-notification,java,android
来源: https://codeday.me/bug/20191028/1955780.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有