I'm making an app which contents should be downloaded from a server. After downloading videos, I want to prevent them from publishing or sharing. I searched about this and find out that putting a dot (.) before the name of the video will hide it from file manager and gallery. But if the user uses a professional file manager would see the videos!
I want a solution to make videos unplayable via other apps.
As far as I Know, you could put your files in your internal directory which is private and only your app can access it.
but still, devices with root access can view and edit your files.
you can get private file location via context.getFilesDir()
You can use cache directory instead of External storage
Ex:
File cacheDir = new File(context.getCacheDir(), DEFAULT_CACHE_DIR);
each app has own cached directory and can accessible only for that app (unless root)
That one simple way to hide media from other apps
more
Related
I have an android application already available on playstore. It is a file transfer app between PC to Android using localhost. I'm using following java function within it:
To create directory/file/show list of files and many other file functions(append, byte read/write etc):
file.mkdir
directory.listFiles();
file.createNewFile()
I had also put
requestLegacyExternalStorage="true"
And it is working fine on android 10 after giving sufficient read/write external storage permission.
But the problem is that these will not work on android 11 as requestLegacyExternalStorage will not work. I have used MANAGE_EXTERNAL_STORAGE and the app works perfect but the problem is that playstore is not allowing it. (Don't know why they rejected the update)
I have also used getExternalFilesDir and it works perfect but don't like data to be in android folder and remove if app is deleted.
I have also tried to use download location and it works but the problem is getExternalStorageDirectory is deprecated:
File file = new File(Environment.getExternalStorageDirectory()+"/"+Environment.DIRECTORY_DOWNLOADS,"FileChat");
So what I wanted to ask how can I manage/use file library for android 11 to read/write/create/delete files and directory. It should not be in android folder as this will be deleted after app is deleted. Can I used public directory like downloads? If I can, what is the alternative to getExternalStorageDirectory()?
I don't need to read user data. Just want to have a directory in which app can store files. The read function is working as file is picked by user using intent.
Thanks in advance.
Top-level directory write access of shared storage is not available in Android 11, however you can use the existing File APIs to access the media and download collection folders like /Pictures, /Downloads, /DICM etc. It won't be possible to create your app's own folder as top level directory but it is possible to create a dedicated sub-directory in the default collection folders.
To keep your app running as expected on Android 10, requestLegacyExternalStorage flag will also be required since access to shared storage on Android 10 was restricted via MediaStore APIs only.
If transfer is only for your apps own files then put them in
File file = new File(Environment.getExternalStoragePublicDirectory(DIRECTORY_DOCUMENTS),"FileChat");
Or use Storage Access Framework to let the user choose and or create a directory on external storage inclusive removable micro sd card.
Android Api 29 has big changes regarding files and folders.
I have not found a way so far to create a folder in the internal storage that is public visible.
Every folder I create can be seen by my app only.
I write an app that creates data files that shall be picked up by other apps, for instance the Total Commander to copy them to a destination.
Everything worked fine until I activated Api 29. Some of my clients DO use pixel phones and they use Android 10.
How can I create a folder and files in Android 10 that are public?
This has been deprecated:
Environment.getExternalStorageDirectory();
Environment.getExternalStoragePublicDirectory(type);
and when I use
File root = context.getExternalFilesDir(null);
The created files can only be seen by my app.
How can I achieve the behavior that was valid before Android 10?
Thanks in advance.
when I use File root = context.getExternalFilesDir(null); The created files can only be seen by my app
They can be seen by any app that uses the Storage Access Framework (e.g., ACTION_OPEN_DOCUMENT), if the user chooses the document that you place in that directory.
I write an app that creates data files that shall be picked up by other apps
Other apps have no access to external or removable storage on Android 10, except in the limited directories like getExternalFilesDir() or via non-filesystem means (ACTION_OPEN_DOCUMENT, MediaStore).
How can I create a folder and files in Android 10 that are public?
Use getExternalFilesDir() and related methods on Context. Or, use ACTION_CREATE_DOCUMENT or ACTION_OPEN_DOCUMENT_TREE and use the Storage Access Framework. In either case, the resulting documents can be used by other apps that also use the Storage Access Framework.
Starting from Android 10, you should use SAF, and let user choose the directory using ACTION_OPEN_DOCUMENT_TREE.
If you need a simple example. You can find it here
Alternatively, you could use requestLegacyExternalStorage = true in manifest when your app is not newly released. But, this is something that should not be used for future release, as this is a short-term solution provided by Google.
Note: In future releases of Android, user will not be able to pick the whole external file directory and Downloads directory, so unfortunately, keep in mind that we are not going to have access to these as well! For more information you can click here
I'm creating an application to download some music files. How do I save it to the internal storage, to be visible to the user using his file manager?
I searched in all the web, and I found that using the Downloads Manager I can only save files in the internal storage, and using another ways, I couldn't save that in place that the user can see.
I tried all the ways from here: Android - how to download file from webserver, but nothing worked for me...
I expect to save that in a visible place in the internal storage, but I can only save in the external storage, and in the app's dir, which is not visible to the regular user.
I am making a chat app that stores sent images in it's private folder on external storage. After saving an image the Google Photos app notices that and asks if the user wants to backup that folder.
Is there a way to prevent that?
'.nomedia' file does not help.
Kindof, Google backup reads imgs and video types.
There are 3 workarounds that I know,
Make the Folder hidden.
Add "." before the folder name. (when u create the folder)
Have a lot of folder hierarchy.
Example: /0/AppName/sentimgs/ <- Can be read by google backup
/0/AppName/bla/bla/bla/sentimgs/ <- Cant be read.
Save the img without an extension. And make ur app add it when they want to view it.
The Shank's first solution worked for me.
However, I noticed that I created .nomedia file wrong, so after fixing it the backup problem has been also solved.
Background
I am developing an android application that will only be used on Nexus 7 tablets (my team is also providing and has access to the hardware).
Problem
The app needs to be flexible to allow content to be added (by non-tech savvy users) to the app and accessed without an internet connection.
Our Idea
Android devices have a file system. We want to design a file system layout such that the people adding content to the application can drag and drop into the correct folder.
e.g.
AppName
Images
Videos
If the user adds a video to the videos folder of the device under our app, it will show up in the app.
We understand that this could easily go wrong (accidentally delete a folder, etc.) but this is out best attempt to solve this without having to update the app ourselves whenever new content comes up (and remember, no internet connection!).
The Question
Is it possible to access the android file system contents and insert them into an app as described in the "Our Idea" section? If so, how?
Yes. This is possible if you don't bother about content security. You can copy the content to any of the file system path in sdcard and your app can look for the folder and read the files .
Example , you can create a folder in sdcard as
sdcard/appname/media/
and create a layout to access the files in the device, and when user selects the files provide option to copy it to your sdcard/appname path.
Check this link
http://developer.android.com/training/basics/data-storage/files.html
Note : the sdcard path can be accessed if you connect to any external system ( PC).