0

The app I'm building is for playing videos, but it needs the ability to download the videos so they can be watched when the user is not connected to the internet.

Whenever my phone downloads a file it goes to the phone's downloads folder, but I want the downloaded file to only be able to be accessed from the app.

Can someone point me in the right direction? All my searches lead to apps for downloading videos.

ZhaoYiLi
  • 173
  • 1
  • 9
  • Personally, I wouldn't like an app that does this kind of 'lock in'. If it goes to the downloads file, it can still play it when the phone is offline. – user3791372 Aug 06 '14 at 21:19
  • 1
    I'm building the app for a client and it's in the specs. :/ – ZhaoYiLi Aug 06 '14 at 21:20
  • you'll have to do without the downloadmanager – njzk2 Aug 06 '14 at 21:21
  • Also, wouldn't the video have to be wrapped in a propriety container format? If not, the video file could be played via a simple file manager that allows the user to search the device? – user3791372 Aug 06 '14 at 21:22
  • Please explain *how* you are downloading the video today. `DownloadManager`? – CommonsWare Aug 06 '14 at 21:24
  • @CommonsWare I haven't written code for downloading the videos yet. I'm trying to find information on what would be the best way to achieve it, since I don't have a lot of android experience and I'm not sure where to start. – ZhaoYiLi Aug 06 '14 at 21:28
  • Note that all of these protections are very weak. Power users typically will be able to get at files anywhere on the device. – Chris Stratton Aug 06 '14 at 21:47

2 Answers2

1

Saving files that are app-private

If you are handling files that are not intended for other apps to use (such as graphic textures or sound effects used by only your app), you should use a private storage directory on the external storage by calling getExternalFilesDir().

This method also takes a type argument to specify the type of subdirectory (such as DIRECTORY_MOVIES). If you don't need a specific media directory, pass null to receive the root directory of your app's private directory.

Beginning with Android 4.4, reading or writing files in your app's private directories does not require the READ_EXTERNAL_STORAGE or WRITE_EXTERNAL_STORAGE permissions. So you can declare the permission should be requested only on the lower versions of Android by adding the maxSdkVersion attribute:

<manifest ...>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"
                 android:maxSdkVersion="18" />
...
</manifest>

Note: When the user uninstalls your application, this directory and all its contents are deleted. Also, the system media scanner does not read files in these directories, so they are not accessible from the MediaStore content provider. As such, you should not use these directories for media that ultimately belongs to the user, such as photos captured or edited with your app, or music the user has purchased with your app—those files should be saved in the public directories.

Refer: http://developer.android.com/guide/topics/data/data-storage.html#filesExternal

AnkitSomani
  • 1,104
  • 7
  • 9
0

using getFilesDir() would work.Check this image from official android docs

but using getExternalFilesDir files were still accessible using file manager in android -> package_name_folder, by using getFilesDir we cannot access those from outside, file manager included.