- Bitmap image = BitmapFactory.decodeByteArray(img.getData(), 0,
- img.getData().length);
- if (image == null) {
- int size = img.getData().length;
- String ssize = size + " byte";
- if (size > 1) {
- ssize = size + " bytes";
- if (size >= 1000) {
- size = size / 1000;
- ssize = size + " kb";
- if (size > 1000) {
- size = size / 1000;
- ssize = size + " MB";
+ InputStream stream = img.newInputStream();
+ try {
+ Bitmap image = BitmapFactory.decodeStream(stream);
+ if (image == null) {
+ String extra = "";
+ if (img.getSize() <= 2048) {
+ try {
+ extra = ", content: "
+ + new String(img.getData(), "UTF-8");
+ } catch (Exception e) {
+ extra = ", content unavailable";