Java tutorial
//package com.java2s; //License from project: Apache License import android.content.Intent; import android.text.Html; import android.text.Spanned; public class Main { private final static char[] DIGITS = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f', }; private final static int NUM_LEN = 8; private final static int FLAG_NULL = -1; private final static int FLAG_SPANNED = -3; private static void appendIntent(StringBuilder sb, Intent intent) { if (intent != null) { String uri = intent.toUri(Intent.URI_INTENT_SCHEME); String action = intent.getAction(); append(sb, "intent", action, uri); } else { append(sb, (String) null); } } private static void append(StringBuilder sb, CharSequence... data) { for (CharSequence d : data) { if (d != null) { if (d instanceof Spanned) { String s = Html.toHtml((Spanned) d); sb.append(hexStringFromInt(FLAG_SPANNED, NUM_LEN)); append(sb, s); } else { int len = d.length(); sb.append(hexStringFromInt(len, NUM_LEN)).append(d); } } else { sb.append(hexStringFromInt(FLAG_NULL, NUM_LEN)); } } } /** * Return the hex string for specified integer. * @param i * @param minWidth * @return the hex string like 0f3e */ public static String hexStringFromInt(int i, int minWidth) { final int len = 8; char[] buf = new char[len]; int cursor = len; do { buf[--cursor] = DIGITS[i & 0x0f]; } while ((i >>>= 4) != 0 || (len - cursor < minWidth)); return new String(buf, cursor, len - cursor); } }