I am building an app that downloads some attachments, like mp4, mp3, docx, pdf, etc, from the server and saves them in the directory returned by getApplicationContext().getDir(), which makes it secure from using it outside this app.
But, I need the attachments to be opened by external applications, like the videos should be opened in video player, mp3's in music player, pdf in pdf readers, etc.
But, currently, the present directory does not let external apps access these attachments. So, is there a way to let these external apps access them, only when I open these attachments using my own app?
Or, is there a way to save the attachments in external directory, like SD card, but it still is secure, i.e., external apps cannot open the attachments. Only when I open these attachments using my own app, it grants permission to other apps that it can now open the attachment. It should be like online streaming, the user cannot access data outside the app.
How can it be implemented?
Take a look at this post - FileProvider will solve your problem.