4

I am trying to send some Extras in my intent with action as ACTION_VIEW but somehow i am not getting it in the target Activity. I tried putting extras both in bundle and without bundle(directly in intent object itself.)

Here is the Sample Code:

   Intent  intent = new Intent(Intent.ACTION_VIEW);
   intent.setData(Uri.parse("android-app://" + BuildConfig.APPLICATION_ID + "/<scheme>/<host>/<path prefix>/" + item.data.offerId));      
   intent.putExtra(Constants.EXTRA_KEY_IS_SOURCE_ANALYTICS, analyticsString);
   context.startActivity(intent);

Here is how i am trying to obtain String:

    Intent intent =getIntent();
    String action = intent.getAction();
    String data = intent.getDataString();
    if (Intent.ACTION_VIEW.equals(action) && data != null) {
         mAnalyticsSourceString = intent.getStringExtra(Constants.EXTRA_KEY_IS_SOURCE_ANALYTICS);
      }

The intent is successfully delivered to the target Activity and i am using getIntent() to get the Data which is delivered successfully but the value of Contants.EXTRA_KEY_IS_SOURCE_ANALYTICS is always received as null.

Amritpal Singh
  • 984
  • 2
  • 14
  • 33
  • have you checked analyticsString value while place into Extra – Android Surya Jul 26 '16 at 07:32
  • How are you trying to get the extra? Are you sure you're getting the correct type? Please provide that code, as well as the type for `analyticsString`, if it's not a `String`. – Mike M. Jul 26 '16 at 07:33
  • yes,while sending the intent it contains a value. but while retrieving it is obtained as null – Amritpal Singh Jul 26 '16 at 07:33
  • @MikeM. check edits – Amritpal Singh Jul 26 '16 at 07:38
  • What is the value of `analyticsString`? How are you setting it? Are you sure execution enters your `if` block? Probably just a typo, but you have `Contants` in one spot, and `Constants` in the other. Are those supposed to be the same? That is, you don't accidentally have two different `EXTRA_KEY_IS_SOURCE_ANALYTICS` keys, do you? – Mike M. Jul 26 '16 at 07:46
  • @MikeM. Corrected Constants typo in the question and i have checked the entire piece. This seems to be happening with my every deeplinked activity which i am trying to open on click of my Notification, but none of them is getting intent extras. – Amritpal Singh Jul 26 '16 at 07:53
  • Oh, this is happening with a `Notification`? Are you setting an appropriate flag on the `PendingIntent`, so that the `Intent` is updated correctly, if needed? – Mike M. Jul 26 '16 at 07:56
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/118290/discussion-between-amritpal-singh-and-mike-m). – Amritpal Singh Jul 26 '16 at 08:50
  • @MikeM. I was able to figure out how to handle this. As per Google's documentation, we have to provide :///path_prefix in the intent and we can pass Extras with this and it works perfectly fine. But as per the app-indexing format which is android-app://// when we fire intent using this uri, it doesn't deleiver any extra thus we can pass those extras as query params of the URL itself – Amritpal Singh Aug 03 '16 at 10:53

0 Answers0