Collect all the Extras from an Intent

Asked

Viewed 112 times

2

Is there any way to find out what all the Extras of an Intent are!

CONTEXT:

I have an app that gets url’s shared by other apps:

if (Intent.ACTION_SEND.equals(action)) {

    final String url_ = i.getStringExtra(Intent.EXTRA_TEXT);
    if(null != url_){
        urls.add(url_);
    }
}

I wanted to know what parameters besides Intent.EXTRA_TEXT this Intent have?

  • Like so all the Extras? You want to know which extras were registered using Intent or all the statics related to Intent?

  • All extras that were registered using Intent

  • See the answer, I made an edit inserting the part of the extras registered.

1 answer

5


For those who are not yet familiar, the Intent's enable information to be transmitted from one screen to another, as the user navigates through the application.

One Intent is an abstract description of an operation to be performed.

According to the documentation, follows below the current values of type EXTRA_[...] which can be used as extra data via putExtra (String, Bundle) using the class Intent. Remembering that it is not only these that can be passed via Intent. Behold:

  • EXTRA_ALARM_COUNT
  • EXTRA_BCC
  • EXTRA_CC
  • EXTRA_CHANGED_COMPONENT_NAME
  • EXTRA_DATA_REMOVED
  • EXTRA_DOCK_STATE
  • EXTRA_DOCK_STATE_HE_DESK
  • EXTRA_DOCK_STATE_LE_DESK
  • EXTRA_DOCK_STATE_CAR
  • EXTRA_DOCK_STATE_DESK
  • EXTRA_DOCK_STATE_UNDOCKED
  • EXTRA_DONT_KILL_APP
  • EXTRA_EMAIL
  • EXTRA_INITIAL_INTENTS
  • EXTRA_INTENT
  • EXTRA_KEY_EVENT
  • EXTRA_ORIGINATING_URI
  • EXTRA_PHONE_NUMBER
  • EXTRA_REFERRER
  • EXTRA_REMOTE_INTENT_TOKEN
  • EXTRA_REPLACING
  • EXTRA_SHORTCUT_ICON
  • EXTRA_SHORTCUT_ICON_RESOURCE
  • EXTRA_SHORTCUT_INTENT
  • EXTRA_STREAM
  • EXTRA_SHORTCUT_NAME
  • EXTRA_SUBJECT
  • EXTRA_TEMPLATE
  • EXTRA_TEXT
  • EXTRA_TITLE
  • EXTRA_UID

To redeem all values saved on Intent you can make a foreach traversing the bundle using keySet(). See below:

if (bundle != null) {
    for (String chave : bundle.keySet()) {
        Object value = bundle.get(chave);
        Log.d(TAG, String.format("%s %s (%s)", chave, 
             value.toString(), value.getClass().getName()));
    }
}
  • 1

    Answer was very nice, but I would only change one detail: the first sentence allows the interpretation that only these values can be passed via Intent, but they are public parameters, for specific intents. A priori any key can be passed via extras.

  • 1

    @Thanks Wakim, I edited and improved so that no one can come to confuse.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.