13

I'd like to show a png or jpg I downloaded from the next in an image viewer intent, but can't get it to work.

Bitmap bmp = getImageBitmap(jpg);
String path = getFilesDir().getAbsolutePath() + "/test.png"; 
File file = new File(path); 
FileOutputStream fos = new FileOutputStream(file);
bmp.compress( CompressFormat.PNG, 100, fos ); 
fos.close(); 

Intent intent = new Intent();
intent.setAction(android.content.Intent.ACTION_VIEW);
intent.setDataAndType(Uri.fromFile(new File(path)), "image/png");
startActivity(intent);

I know the bitmap is downloaded ok (use the same routine for supplying it my ImageView instances elsewhere in my app) - I think it wrote to file ok, I can see it on disk and the file size is correct. The intent is launched but an exception is thrown:

ERROR/ImageManager(1345): got exception decoding bitmap java.lang.NullPointerException

then the new activity just sits there, blank. How does this work?

Derlin
  • 9,572
  • 2
  • 32
  • 53
Mark
  • 39,551
  • 15
  • 41
  • 47

2 Answers2

25

Check out Android issue 2092 it sounds similar to what you are describing. The issue states, "Bitmap.compress() fails for PNG files saved in Indexed Color Mode (instead of RGB color mode)", however the first commenter thinks that, "it looks like its not an indexed color problem but a PNG problem."

It looks like your code is fine, compare it to this Android snippet:

Intent intent = new Intent();  
intent.setAction(android.content.Intent.ACTION_VIEW);  
File file = new File("/sdcard/test.mp4");  
intent.setDataAndType(Uri.fromFile(file), "video/*");  
startActivity(intent);   

Intent intent = new Intent();  
intent.setAction(android.content.Intent.ACTION_VIEW);  
File file = new File("/sdcard/test.mp3");  
intent.setDataAndType(Uri.fromFile(file), "audio/*");  
startActivity(intent); 
David Glass
  • 2,334
  • 1
  • 25
  • 35
  • 1
    If I want to play more number of videos one by one how can Play video one after another is it possible intent( , "video/*"); – Anand Phadke Apr 18 '13 at 06:47
  • 3
    @andrewww great question, I think you should ask that as a new question. I'm not sure, but I'm sure someone here will know. They'll never see it in this comment though. – David Glass Apr 22 '13 at 21:31
4

Another problem may be permissions on the file. Typically your /data/data/[app]/ directories are not world readable, and are owned by you applications "app_XX" user/group. Either make sure your permissions are correct, or make sure the file is in a place that both applications can read (emms, or sd card)

wuntee
  • 12,170
  • 26
  • 77
  • 106