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.
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();
}
}
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");
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With