I am wondering if there is a built-in feature that does this or if I need to home-roll my own view or use an external library, but let's say I have a designated folder (could be either in internal storage or public/private external storage) and I want to be able to allow the user to view any pictures they have in this folder, select any number of them arbitrarily, delete them if desired, run custom code if a picture is clicked, etc.
You need to design that on your own. There's no in-built file explorer/file manager provided by android APIs.
Related
Scenario an App create documents and has to store and open them.
Before SAF creating a MyAppDocument folder, where the App can store and open every file, was a smooth operation,
now with SAF if I use the intent with ACTION_OPEN_DOCUMENT_TREE in order to get access to the storage place where this folder must be created:
1- Appears the directory access picker dialog
2- If picker is positioned on main storage path(both internal or external sd card) and I target latest Android API level 30, the path cannot be selected and appears also an additional intimidating privacy warning that invite user to create a new folder or select another path to avoid privacy problems as shown in the picture (absurd considering that is supposes to be an user space not some system root directory)
The user can still follow the suggestion to choose a different path or create another folder then choose such path, but this is horrible for user experience, and many users will uninstall the app bothered or scared.
Is there another way to create a folder for the App that can be easily accessible by the user file manager\other apps(so the user can easily copy, open and move and manage files created inside it) without asking so many manual actions to the user?
My requirement is to cache the files securely in android internal/external storage, where apps other than my app should not view/access the documents I store.
Current implementation:
Currently, the app uses context.getExternalCacheDir() as a base directory and followed by respective folder structure to cache files. The problem here is, any user can view the files stored by just navigating through the path using some File Explorer apps.
We can use context.getCacheDir() or file directory,
There are limitations in using it, as it has less space and the platform might automatically delete files when it wants space for other operations.
Required Implementation:
Encryption/decryption would be one way yet, please suggest other possible ways to cache the files securely, so that users cannot view/access using other external applications.
as it has less space
That is not true for most Android devices created in the last 8 years.
the platform might automatically delete files when it wants space for other operations
That also holds true for getExternalCacheDir().
please suggest other possible ways to cache the files securely, so that user cannot view/access using other external application
Use getFilesDir().
I have a project consisting of four programs for different platforms; all of them use the same XML-based settings file format. I want to be able to manually modify/overwrite it outside of the application. On Windows, Windows Mobile and Linux I'm using "user.home", but on Android that alias isn't implemented. I'm thinking about simply putting it in the Downloads directory, however, that doesn't feel right.
I can't be the only one, who needs that kind of functionality. Or this isn't Android-way? Any suggestions are appreciated.
EDIT: I'm OK with the settings file not being available all the time (i.e. SD-card removed), it's used only on the start-up of the application.
Store it in getExternalFilesDir(). This would work only if the device has an external storage. The user would be able to access it.
However, take note of the following from the docs:
External files are not always available: they will disappear if the
user mounts the external storage on a computer or removes it. See the
APIs on Environment for information in the storage state.
According to Android data storage documentation you have 5 options:
Shared Preferences. By default this will use file /data/data/your.package.name/preferences/user_preferences.xml
Internal Storage. Here you can use something like /data/data/you.package.name/user.home
External Storage. Similar to internal storage /mnt/sdcard/Android/data/your.package.name/user.home, but if user removes memory card file will be inaccessible.
SQLiteDatabase. You can store the whole user.home file in a database blob.
NetworkConnection. Store user's config in a cloud.
do you know how to create a folder in which photos will be saved and os and other apps should see that folder as photo album? I need to save photos in a certain album and if album does not exists, I need to create it.
Thanks
If you store images files anywhere on the external storage (with the exception of locations that also contain a .nomedia file), the media scanner, and thus the built-in "Gallery" app, will locate them and display them.
To be a good citizen you should place such files in the recommended location on the external storage using getExternalStoragePublicDirectory. You can pass that DIRECTORY_PICTURES for images.
Be advised though, that stuff is only available as of API level 8. If you need to also support earlier API versions you can use getExternalStorageDirectory and still use the correct recommended path on your own.
And, as always, you need to make sure the external storage is available before you try to write to it.
I would like to show a list of files in the Android phone.
For example, i would like my app to be able to list all images stored in the phone, i dont want a gallery view, just a simple list.
I would also like to be able to show all the audio files
any help would be appreciated
Thanks
I'm assuming you mean on external storage. Read up on Data Storage, which will tell you the correct way to go about navigating the file-system.
If you're using API Level 8 or
greater, use getExternalFilesDir() to
open a File that represents the
external storage directory where you
should save your files. This method
takes a type parameter that specifies
the type of subdirectory you want,
such as DIRECTORY_MUSIC and
DIRECTORY_RINGTONES (pass null to
receive the root of your application's
file directory). This method will
create the appropriate directory if
necessary. By specifying the type of
directory, you ensure that the
Android's media scanner will properly
categorize your files in the system
(for example, ringtones are identified
as ringtones and not music). If the
user uninstalls your application, this
directory and all its contents will be
deleted.
If you're using API Level 7 or lower,
use getExternalStorageDirectory(), to
open a File representing the root of
the external storage.
For standard/common media types such as Music, video and images in the internal memory, there are respective ContentProviders in the system that manage them. If you want to build list of such items you should consider querying respective ContentProviders (Google for MediaStore Provider).
However, if you want to build an exhaustive list of all the files in a particular directory, internal or external, you can use File#listFiles() API as was suggested by Fredley above.