0

I have a number of videos streamable from different URL links. I want to be able to download these videos using the DownloadManager class so that the downloaded videos can be PRIVATE and ONLY ACCESSIBLE by the app. I understand setting the DownloadManager.request as below

request.setDestinationInExternalPublicDir(Environment.DIRECTORY_DOWNLOADS, "fileName");

will make the downloaded video accessible by other apps, but THAT IS NOT WHAT I WANT. I want the downloaded videos to only be accessible by my app. I would really appreciate it if anyone can help with how I can achieve this

Eric
  • 37
  • 1
  • 7

2 Answers2

0

store your file on the app's data folder, this path : ContextWrapper.getFilesDir();

Code Demon
  • 1,256
  • 1
  • 9
  • 15
  • thanks, @Thompson sparta, I forgot to add that I'm not very experienced at this. If you wouldn't mind expanding, HOW would I add this to the DownloadManager? – Eric Jul 14 '20 at 10:20
0

I want to be able to download these videos using the DownloadManager class so that the downloaded videos can be PRIVATE and ONLY ACCESSIBLE by the app

That is not possible — if it is "PRIVATE and ONLY ACCESSIBLE by the app", then DownloadManager does not have access to it. Your choices are:

  • Download using DownloadManager to a public location, perhaps later moving the downloaded content to a private location

  • Download the content to a private location yourself, such as using OkHttp

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
  • Let's assume I want to download the video using OkHttp, How do I direct it to a private location as spelled in the question above? – Eric Jul 14 '20 at 11:47
  • @Eric: [The OkHttp answer that I pointed you to](https://stackoverflow.com/questions/25893030/download-binary-file-from-okhttp/29012988#29012988) is downloading its file to `getCacheDir()`. That is part of [internal storage](https://commonsware.com/blog/2019/10/06/storage-situation-internal-storage.html) and it is only accessible to your app (except on rooted devices). – CommonsWare Jul 14 '20 at 12:10
  • Thanks for your reply, it's adding up now. One more clarification; I read somewhere that the files(in this case, video) stored in the getCacheDir() gets deleted if the app system deems it necessary, Instead of the getCacheDir(), can I call getFileDir() instead?, if yes, will it the file be stored private to app same as the getCache()? – Eric Jul 14 '20 at 15:16
  • @Eric: Yes. Any of the internal storage locations listed in that blog post have the same effect. – CommonsWare Jul 14 '20 at 16:12
  • thanks a lot, @CommonsWare. you have been more than helpful. I will try using this knowledge to download some sample Videos. – Eric Jul 14 '20 at 16:20
  • I tried the OKHTTP and it keeps giving error. Below is the Error log "I/DOWNLOAD ERROR: socket failed: EPERM (Operation not permitted)" – Eric Jul 14 '20 at 18:15
  • @Eric: Probably you need to add the `INTERNET` permission to the manifest. – CommonsWare Jul 14 '20 at 18:45
  • Yes, I have long provided internet permission in the manifest.xml – Eric Jul 14 '20 at 19:13
  • @Eric: Bear in mind that `I/` is an informational message and may not necessarily indicate a problem. Moreover, it feels like something that you perhaps logged yourself, without logging the stack trace of a caught exception. Beyond that, I recommend that you ask a separate Stack Overflow question with a [mcve] showing what you have tried. – CommonsWare Jul 14 '20 at 19:49