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

时间:2014-12-03 01:41:01

标签: java android parse-platform push-notification

我已经设置了解析推送通知,当我尝试打开它时,我的应用程序崩溃,现在我找到了一个关于我创建一个新的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);

我怎么能摆脱这种折旧的方法我已经看过这个问题,我得到了一些帮助,但它没有回答关于折旧方法的这一部分。 Exception when opening Parse push notification

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

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

感谢您的帮助。

1 个答案:

答案 0 :(得分:0)

您正在继承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构建通知。所以在发件人方面没有警报和标题。

阅读管理推送生命周期@

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

参考

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

相关问题