I have been stuck on a problem for almost 1 week, so I allow myself to call on you.
I would like from an application that I am currently developing, to be able to open a file of any type of extension from the internal storage of the phone.
Example in picture:
If I click on an .mp3 file from my application that I am developing, Android would have to recognize the type and automatically suggest applications on my phone that can play the file:
"Ouvrir avec" means Open With
The same goes for the other types.
PDF:
Do you have a solution to answer my problem?
I tried many attempts, my last was this:
String path = "/storage/emulated/0/Download/Cours1.pdf";
Intent intent = new Intent();
intent.setAction(Intent.ACTION_VIEW);
intent.setDataAndType(Uri.parse("content://" + path), "application/pdf");
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
intent.addFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION);
getApplicationContext().startActivity(intent);
But my file does not open:
2
Answers
Try adding this :
Your final code should look like this:
Edit 1:
Here is what I use (it works fine with me):
path
andmimeType
areString
sEdit 2:
replace
"content://"
with"file://"
If it worked please accept the answer and upvote it so more people can find it.
You can do something like this:
First go to manifest file and write the following tag under the
<application>
tagThen create a
xml
folder inres
and create a file named:providerpaths.xml
and then copy paste the code:In java
How to use