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.
Baca Juga
- Android 11: Primary Directory (invalid) Not Allowed For Content://media/external/file Allowed Directories Are [download, Documents]
- How Exactly Does Jvm Compile Ternary Operators? Should I Be Concerned About Different Api Versions?
- Pass Data To Another Fragment By Swipe View With Tab Android Studio,not Button
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"