View image with intent ACTION_VIEW?

I want to show png or jpg, which I downloaded from the following with the intention of viewing images, but I can not 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 that the bitmap is loaded in order (use the same procedure to deliver it to ImageView instances elsewhere in my application). I think he wrote the file in order, I see it on disk, and the file size is correct. Startup started, but an exception is thrown:

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

then the new activity just sits there, empty. How it works?

+12
android
Nov 16 '09 at 7:37
source share
2 answers

Check out Android question 2092 , this is similar to what you are describing. The problem is that "Bitmap.compress () does not work for PNG files saved in indexed color mode (instead of RGB color mode)," however the first commenter thinks that "it seems that this is not an indexed color problem, but a problem with PNG. "

It looks like your code is fine, compare it with 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); 
+24
Dec 13 '09 at 3:13
source share

Another issue may be file permissions. Usually your / data / data / [app] / directories are not readable in the world and belong to your app_XX user / group applications. Either make sure that your permissions are correct, or make sure that the file is in a place that both applications can read (emms or SD card).

+4
Sep 23 2018-11-11T00:
source share



All Articles