无法读取Parse推送通知包数据

Aab*_*ani 5 android json push-notification parse-platform

我正在尝试使用Parse推送通知服务发送自定义数据,但是从Bundle中提取时始终返回空值.

自定义广播接收器:

    @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);
}
Run Code Online (Sandbox Code Playgroud)

宣言声明:

        <receiver
        android:name=".receiver.NotificationReceiver"
        android:exported="false">
        <intent-filter>
            <action android:name="link_notification"/>
        </intent-filter>
    </receiver>
Run Code Online (Sandbox Code Playgroud)

我从解析仪表板发送以下JSON:

{ "dataString": "objectId", "heading": "type", "action": "link_notification" }
Run Code Online (Sandbox Code Playgroud)

当我记录Bundle数据时,我能够看到标题dataString,但无法访问它.该包总是返回null.

请帮忙!谢谢.

Man*_*ani 16

JSON将是额外的字符串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();
    }
}
Run Code Online (Sandbox Code Playgroud)