Search code examples
androidandroid-intentparcelable

ToUri() not convert all extra in intent (parcelable, serializable, byte[]..)


When i add a array of byte in my intent like this :

Intent intent = new Intent("android.intent.action.MAIN" );

Bundle param = new Bundle();

ByteArrayOutputStream bs = new ByteArrayOutputStream();

bmp.compress(Bitmap.CompressFormat.PNG, 50, bs);

param.putByteArray("image",bs.toByteArray());

intent.putExtras(param);

The data of bitmap nerver appear in the encoded uri :

String uri = intent.toUri(URI_INTENT_SCHEME);

(uri) -> intent:#Intent;action=android.intent.action.MAIN;launchFlags=0x10000000;component=com.xxxx.xxx/.activity.xxxx;end

Thanks in advance.


Solution

  • Array extras are not supported in Intent.toUri(). Only the following types are supported (this is taken from the source code for Intent.toUri():

                char entryType =
                        value instanceof String    ? 'S' :
                        value instanceof Boolean   ? 'B' :
                        value instanceof Byte      ? 'b' :
                        value instanceof Character ? 'c' :
                        value instanceof Double    ? 'd' :
                        value instanceof Float     ? 'f' :
                        value instanceof Integer   ? 'i' :
                        value instanceof Long      ? 'l' :
                        value instanceof Short     ? 's' :
                        '\0';