我在推送通知中发送数据后无法接收JsonObject

时间:2016-01-14 08:47:32

标签: java android parse-platform notifications push

我在这里发送推送:

ParsePush parsePush = new ParsePush();
ParseQuery parseQuery = ParseInstallation.getQuery();
parseQuery.whereEqualTo("UserId", userId);
JSONObject data = new JSONObject();
try {
    data.put("Name", objects.get(0).fetchIfNeeded().get("Name").toString());
    data.put("Amount", arr.get(ii + 1));
    data.put("Date", arr.get(ii+2));
    data.put("Time", arr.get(ii+3));
    data.put("Location",  objects.get(0).fetchIfNeeded().get("Address").toString());
    parsePush.setData(data);
} 
catch (Exception ex) {
}

parsePush.sendMessageInBackground("blah blah blah", parseQuery);

当我尝试在onPushOpen收到它时,我找不到数据,当我转到JSON时我得到了异常。

public class ParsePushReceiver extends ParsePushBroadcastReceiver{

@Override
public void onPushOpen(Context context, Intent intent) {
    Intent i = new Intent(context, MainActivity.class);
    if (intent != null) {
        try {
            JSONObject json = new JSONObject(intent.getExtras().getString("com.parse.Data"));
            String name = json.getString("Name");
            String amount = json.getString("Amount");
            String date = json.getString("Date");
            String time = json.getString("Time");
            String location = json.getString("Location");
            i.putExtra("Name", name);
            i.putExtra("Amount", amount);
            i.putExtra("Date", date);
            i.putExtra("Time", time);
            i.putExtra("Location", location);
            context.startActivity(i);
        } catch (Exception ex) {
        }
        i.putExtras(intent.getExtras());
        i.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
        context.startActivity(i);
    }
}

以下是例外:

  

java.lang.NullPointerException:尝试在空对象引用上调用接口方法'java.lang.Object [] java.util.Collection.toArray()'

我认为清单是好的,不是问题,因为接收器正在工作,除了数据问题。

0 个答案:

没有答案