Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/194.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Android-解析推送通知在打开时崩溃_Java_Android_Parse Platform_Push Notification - Fatal编程技术网

Java Android-解析推送通知在打开时崩溃

Java Android-解析推送通知在打开时崩溃,java,android,parse-platform,push-notification,Java,Android,Parse Platform,Push Notification,我已经设置了parse push通知,当我试图打开它时,我的应用程序崩溃了,现在我发现了一个解决方法,可以创建一个新的java类并覆盖onPushOpen,如下所示: public class Receiver extends ParsePushBroadcastReceiver { @Override public void onPushOpen(Context context, Intent intent) { Intent i = new Intent(c

我已经设置了parse push通知,当我试图打开它时,我的应用程序崩溃了,现在我发现了一个解决方法,可以创建一个新的java类并覆盖onPushOpen,如下所示:

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);
    }
}
但是为了仍然接收推送通知,我仍然需要在MyApplication.java类PushService.setDefaultPushCallbackthis,MainActivity.class中使用这个折旧方法

我怎样才能摆脱这种折旧方法呢?我已经研究了这个问题,在那里我得到了一些帮助,但它没有回答关于折旧方法的这一部分

我在想,也许这种方法可能会被过度使用,但我不确定它是否能敏锐地处理接收推送,或者在收到推送后处理更多推送

@Override
    public void onPushReceive(final Context c, Intent i) {
        // Handle the received push
    }
提前感谢您的帮助。

您正在对ParseReceiver进行子类化

然后在舱单上

    <receiver
        android:name=".Receiver " // your broadcastreceiver
        android:exported="false" >
        <intent-filter>
            // youtr actions
        </intent-filter>
    </receiver>
注意:如果在推送中指定了警报或标题,则使用getNotification构造通知。因此,发件人端没有提示和标题

读取和管理推送生命周期@

参考文献


. 您使用的是什么parse jar版本?@Raghunandan我使用的是1.7.1最新版本,我已经按照快速步骤指南查看了文档,如果您查看方法PushService.setDefaultPushCallback,它会说它贬值了。这是不需要的。您有自定义的广播接收器。您所需要做的就是在那里显示通知。@Raghunandan但当我删除该行时,我将无法再接收通知。那么,你是说我应该用什么来替换它呢?在新的JSONObject行中,我得到编译错误unhadded exception org.JSON.JSONException和extras=intent.getExtras;complie错误无法解析符号extras@iqueqiorio您需要将附加声明为Bundle extra。它还取决于您如何在发送方发送数据。你使用json吗。我只是通过云代码发送文本字符串,所以不,我只是发送纯文本。所以我不需要JSON部分吗?@iqueqiorio阅读文档。如果您只需要推送通知,则不需要子类ParsePushBroadcastReceiver。确保您具有警报和标题,并且将显示通知。如果您需要自定义notification子类ParsePushBroadcastReceiver,然后自己处理通知部分。再次阅读文档我已经阅读并重新阅读了文档,但是当我删除setDefaultPushCallback折旧方法时,我无法收到推送通知?
public class Receiver extends ParseBroadcastReceiver {

@Override
public void onReceive(Context context, Intent intent) {

    super.onReceive(context, intent);

        extras = intent.getExtras();
        if(intent.hasExtra("com.parse.Data")) 
        {
            try
            {
             json = new JSONObject(intent.getExtras().getString("com.parse.Data"));
             int notificationtype = json.getInt("notificationtype"); // this is send on the sender side
             switch(notificationtype)
             {
              case 1:

                    // show your custom notification. Refer android notification guide 

                break;
                case 2:
                //rest of the code