Created
September 21, 2017 10:46
-
-
Save MediumOne/ee81aaba5a3101e57451957581f99df7 to your computer and use it in GitHub Desktop.
Code to print/log contents of an Intent in Android
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.example.test; | |
import android.content.Intent; | |
import android.os.Bundle; | |
import android.util.Log; | |
import java.util.Set; | |
import static android.content.Intent.URI_INTENT_SCHEME; | |
public class IntentLogger { | |
private static final String TAG = "IntentLogger"; | |
public static void logFullContent(Intent intent) { | |
// Log.v(TAG, "Intent.toString(): " + intent.toString()); | |
// Log.v(TAG, "Intent.toUri(): " + intent.toUri(URI_INTENT_SCHEME)); | |
Log.v(TAG, "Package: " + intent.getPackage()); | |
Log.v(TAG, "Action: " + intent.getAction()); | |
Log.v(TAG, "Type: " + intent.getType()); | |
printCategories(intent.getCategories()); | |
Log.v(TAG, "Component: " + intent.getComponent()); | |
Log.v(TAG, "Data String: " + intent.getDataString()); | |
printExtras(intent.getExtras()); | |
} | |
private static void printExtras(Bundle extras) { | |
if(extras == null){ | |
Log.v(TAG, "Extras: null"); | |
} else { | |
if(extras.isEmpty()){ | |
Log.v(TAG, "Extras: not null, but empty"); | |
} else { | |
for(String extraKey : extras.keySet()){ | |
Log.v(TAG, "Extra: " + extraKey + ": " + extras.get(extraKey)); | |
} | |
} | |
} | |
} | |
private static void printCategories(Set<String> categories) { | |
if(categories == null){ | |
Log.v(TAG, "Categories: null"); | |
} else { | |
if(categories.isEmpty()){ | |
Log.v(TAG, "Categories: not null, but empty"); | |
} else { | |
for(String category : categories){ | |
Log.v(TAG, "Category: " + category); | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment