Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot read Parse push notification bundle data

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

Custom Broadcast Receiver:

    @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);
}

Manifest Declaration:

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

And i am sending the following JSON from parse dashboard:

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

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.

Please help! Thanks.

like image 313
AabidMulani Avatar asked Oct 16 '14 19:10

AabidMulani


2 Answers

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();
    }
}
like image 97
Manish Mulimani Avatar answered Sep 18 '22 15:09

Manish Mulimani


Okay, now i get it. To get your Json String, you need to do this :

public void onReceive(Context context, Intent intent) {
    // TODO Auto-generated method stub
    Bundle extra = intent.getExtras();
    String json = extra.getString("com.parse.Data");
}
like image 31
Tsunaze Avatar answered Sep 17 '22 15:09

Tsunaze