Before Android N
in my app after downloading a file I open it like:
Intent myIntent = new Intent(Intent.ACTION_VIEW);
File myFile = new File(result);
String mime = URLConnection.guessContentTypeFromStream(new FileInputStream(myFile));
myIntent.setDataAndType(Uri.fromFile(myFile), mime);
myIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
context.startActivity(myIntent);
Since Android N
if I use this code I get an FileUriExposedException
, as suggested here I should use the FileProvider and get the path like:
Uri contentUri = getUriForFile(getContext(), "com.mydomain.fileprovider", newFile);
and then open it with:
ParcelFileDescriptor.openFile(Uri uri,String mode)
as suggested here where it says Uri: A content URI associated with a file, as returned by getUriForFile().
But in the IDE if I do ParcelfileDescriptor.open...
there is no method openFile()
only open()
with a File as parameter, and no uri. So how I can open a file in Android N?
Note: I don't want to open a file with my application. For example if I download a pdf, I want to open it with the installed app on the phone.