I've successfully implemented advance targeting with JSONObject and able to send and receive notifications. I also set my default callback PushService.setDefaultPushCallback(this, myActivity.class);.
I have a BroadcastReceiver
and onReceive()
which will access all the data passed via the payload. I also have an Intent inside the onReceive function which will fire up an activity with some additional data passed to that activity via putExtra();
.
My problem now is that when i receive the notification, it automatically start the intent activity which i've stated in the onReceive()
function. What i want to do is to start the onReceive's intent activity only if the user Tap/Click on the push notification message on the system tray.
I tried so many ways to solve this yet i keep on failing. Any suggestions? I can provide additional code if needed. Thank you.
EDIT: The intent's activity should start when the user tap on the push notification no matter if the app is on the foreground or background. Thanks.
Well, i decided to paste my onReceive() here :
@Override
public void onReceive(Context context, Intent intent) {
try {
JSONObject json = new JSONObject(intent.getExtras().getString("com.parse.Data"));
Iterator itr = json.keys();
ArrayList arraylist = new ArrayList();
while (itr.hasNext()) {
String key = (String) itr.next();
arraylist.add(json.getString(key));
}
Intent intentComment = new Intent(context, comments.class);
intentComment.putExtra("post_id", arraylist.get(3).toString());
intentComment.putExtra("btnFlag", arraylist.get(2).toString());
intentComment.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(intentComment);
} catch (JSONException e) {
Log.d(TAG, "JSONException: " + e.getMessage());
}
}