Here is my code
Uri fileUri = Uri.fromFile(file);
Intent intent = new Intent();
intent.setAction(Intent.ACTION_VIEW);
intent.setData(fileUri);
startActivity(intent);
So, it opens a file that I specify within my app. First few files I tested it on were – pdf ones and it worked just fine. And now, and I know it is complete bonkers, every time I choose anything different from pdf – it apparently tries to use a program for the pdf files to open the chosen file and gives me this message
The document cannot be opened because it is not a valid PDF document
Funny thing 🙂 Any ideas what is going on?
Use Intent.setType to set the mimetype of each file that you are trying to open. So that only app that can handle the particular mimetype will be opened
Edit: You can use MimeTypeMap.getMimeTypeFromExtension to get the Mimetype of the file.