Android – Listing all extras of an Intent

androidandroid-intent

For debugging reasons I want to list all extras (and their values) of an Intent. Now, getting the keys isn't a problem

Set<String> keys = intent.getExtras().keySet();

but getting the values of the keys is one for me, because some values are strings, some are boolean… How could I get the values in a loop (looping through the keys) and write the values to a logfile? Thanks for any hint!

Best Answer

Here's what I used to get information on an undocumented (3rd-party) intent:

Bundle bundle = intent.getExtras();
if (bundle != null) {
    for (String key : bundle.keySet()) {
        Log.e(TAG, key + " : " + (bundle.get(key) != null ? bundle.get(key) : "NULL"));
    }
}

Make sure to check if bundle is null before the loop.

Related Topic