繁体   English   中英

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

[英]Android - Parse push notification crashes on open

我已经设置了解析推送通知,尝试打开它时我的应用程序崩溃了,现在我找到了一个解决方法,可以制作一个新的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.setDefaultPushCallback(this, MainActivity.class);此折旧方法PushService.setDefaultPushCallback(this, MainActivity.class);

我如何摆脱这种折旧方法,我在这个问题上得到了一些帮助,但是却没有回答有关折旧方法的这一部分。 打开“解析”推送通知时发生异常

我当时想也许可以改写这种方法,但是我不确定它是敏锐地处理推送内容还是更多地处理推送内容?

@Override
    public void onPushReceive(final Context c, Intent i) {
        // Handle the received push
    }

我在这里先向您的帮助表示感谢。

您在ParsePushBroadcastReceiver

然后在清单中

    <receiver
        android:name=".Receiver " // your broadcastreceiver
        android:exported="false" >
        <intent-filter>
            // youtr actions
        </intent-filter>
    </receiver>

在BroadCastReceiver中

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

注意:如果在推送中指定了“ alert”或“ title”,则使用getNotification构造Notification。 因此,发件人一侧没有警报和标题。

阅读管理推送生命周期@

https://www.parse.com/docs/push_guide#receiving/Android

参考

https://www.parse.com/questions/how-suppress-push-notification-from-being-displayed

暂无
暂无

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

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