无法读取解析推送通知捆绑数据 [英] Cannot read Parse push notification bundle data

查看:159
本文介绍了无法读取解析推送通知捆绑数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想用解析推送通知服务发送自定义数据,但同时从包中提取总是返回空值。

I am trying to send custom data using the Parse push notification service, but while extracting from the Bundle always null values are returned.

自定义广播接收器:

    @Override
public void onReceive(Context context, Intent intent) {
    Log.e("Receiver","Invoked");
    Bundle bundle = intent.getExtras();
    Intent contentIntent = new Intent(context, MainPage.class);
    String alertMsg = bundle.getString("heading"); //never get this value
    String urlString = bundle.getString("dataString"); //never get this value
    contentIntent.putExtra(EXTRA_URL, urlString);
    PendingIntent pendingIntent = PendingIntent.getActivity(context,
            NOTIFY_REQUEST_CODE, contentIntent, PendingIntent.FLAG_ONE_SHOT);
    showNotification(context, notificationId, alertMsg, pendingIntent);
}

清单宣言:

        <receiver
        android:name=".receiver.NotificationReceiver"
        android:exported="false">
        <intent-filter>
            <action android:name="link_notification"/>
        </intent-filter>
    </receiver>

,我从parse仪表盘发出以下JSON:

{ "dataString": "objectId", "heading": "type", "action": "link_notification" }

当我登录的包数据我能够看到标题 dataString ,但不能访问它。束总是返回null。

When i am logging the Bundle data i am able to see the heading and dataString, but cant access it. The bundle is always returning null.

请帮忙! 谢谢你。

推荐答案

JSON的将是额外的字符串 com.parse.Data

The JSON will be in extra string com.parse.Data.

@Override
public void onReceive(Context context, Intent intent) {
    Bundle extras = intent.getExtras();
    String jsonData = extras.getString("com.parse.Data");
    JSONObject jsonObject;
    try {
        jsonObject = new JSONObject(jsonData);
        String heading = jsonObject.getString("heading");
        String dataString = jsonObject.getString("dataString");
    } catch (JSONException e) {
        e.printStackTrace();
    }
}

这篇关于无法读取解析推送通知捆绑数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆