How to open a file in Android via an Intent How to open a file in Android via an Intent android android

How to open a file in Android via an Intent


What is the type of the Attachment in your code? Perhaps it returns wrong mime type?

This code works for me:

File file = new File("EXAMPLE.JPG");// Just example, you should parse file name for extensionString mime = MimeTypeMap.getSingleton().getMimeTypeFromExtension(".JPG");Intent intent = new Intent();intent.setAction(android.content.Intent.ACTION_VIEW);intent.setDataAndType(Uri.fromFile(file), mime);startActivityForResult(intent, 10);


You cannot open files that are not on the sdcard like that.You'll need to copy the file to the sdcard and then opening it.


When setting the location to "openFileOutput("fileName", Activity.MODE_WORLD_READABLE)" it will work. Other apps cannot read the data (even for viewing) stored when setting to "Context.MODE_PRIVATE"

see other post on stackoverflow