Android Java : How To Open A Downloaded File Using FileProvider In Another App
I have the following setup, but when opening the file in third party app, the file is not being found. After downloading a file(In bytes), I store it. public File storeFile(byte[]
Solution 1:
File imagePath = File(getFilesDir(), "downloads");
That is a completely different directory as used in
File f = new File(A.getDir(path, Context.MODE_PRIVATE), "downloads");
Just compare imagePath.getAbsolutePath()
and f.getAbsolutePath()
;
You better do not construct the same path or File
instance twice but use one variable instead.
UPDATE.
I now see that your code is even a bigger mess.
Uri uri = Uri.fromFile(storeFile(bytes, ref));
Uri newUri = FileProvider.getUriForFile(context, "com.do.app.fileprovider", file);
You are not using uri
or newUri
at all but instead contentUri
. And why two/three uries? Change to one.
Uri uri = FileProvider.getUriForFile(context
, "com.do.app.fileprovider"
, storeFile(bytes, ref));
And then put that uri with setDataAndType()
in the used intent.
Post a Comment for "Android Java : How To Open A Downloaded File Using FileProvider In Another App"