Storage on android 11 - java

I want to store images, videos, audio, and all types of documents like (jpg, mp4, gif, txt, pdf, CSV and etc.) in one folder like 'ABC' and store all that in ("ABC") folder.
I have lots of R&D and done from ALL files access(MANAGE_EXTERNAL_STORAGE) permission and working perfectly as I said as above but play store was rejected due to all file access permission.
Play Store Reject Message
Policy: "Access all files" permission
File and directory attributes on your device are considered your personal and sensitive information and are subject to your personal and sensitive information policies and the following requirements:
The access that your app requests should be limited to device storage, which is essential for your app to function. You cannot request access to device storage for third parties for purposes unrelated to essential app features for your users.
Android devices running Android R (Android 11) or later require MANAGE_EXTERNAL_STORAGE permission to manage access in shared storage. Any app that targets R or later and requests a wide range of access to shared storage (“access to all files”) must pass a proper access review before it can be published. Apps that are allowed to use this permission must clearly display a message to the user asking them to enable Access to all files in the Special App Access settings. For more information on this requirement for R, see this help article.
Find out more about the Access All Files permission
Find out Android storage use cases and recommended methods
Please resolve this issue in Google Play Console.
.
Problem: I need to use the Media Store API
The "Access All Files" permission has been requested, but only media files need access for important features of the app. The MediaStore API allows apps to access and interact with media on external storage volumes without the need for "access to all files."
Update your app to use the Media Store API and remove the "Access All Files" (MANAGE_EXTERNAL_STORAGE) permission.
So please help me have anyone idea using Scoped Storage how it works like create a folder on storage like /data/ABC and store all documents as I mentioned like (jpg, mp4, gif, txt, pdf, CSV and etc.)
I want to like please check below steps
Create a folder (not in a folder like pictures, video, audio, document and download as we have on File manager)
Store file and images in "Created Folder"
Store Download File in "Created Folder"
Easily open after download
Update and Delete Image
Please help me through the coding level if you used it because I have lot's of R&D but not get any document so please don't share any document so if you have used please help me because before 29 API levels it's working and on 29 API level I set android:requestLegacyExternalStorage="true" on manifest so I was also worked for me but android 11(30) what we do please give me a proper solution.
Used code like below
final String directoryFolder =
Environment.getExternalStorageDirectory() + "/" + "ABC";
File file = new File(directoryFolder);
if (!file.exists()) {
file.mkdir();
}
getting error like below
com.androidnetworking.error.ANError:
com.androidnetworking.error.ANError: java.io.FileNotFoundException:
/storage/emulated/0/ABC/19429202106171621.pdf: open failed: EPERM
(Operation not permitted)

Related

Read harcoded Uri from external storage

Im trying to read a json file from an external storage without sucess. Im getting the error:
Permission Denial: opening provider com.android.externalstorage.ExternalStorageProvider from ProcessRecord{bfaa1d6 26301:com.plm.valdecillasurdemo/u0a284} (pid=26301, uid=10284) requires that you obtain access using ACTION_OPEN_DOCUMENT or related API
My manifest.xml file is OK
I am checking in runtime for READ_EXTERNAL_STORAGE permission and only read the file when the permission is granted
When I try read the file I getting the related error.
In a second approach I started an ACTION_OPEN_DOCUMENT Intent.
A system dialog ask me for picking a file and all is fine. I read the file correctly however I dont want be asked for a Uri. My Uri is hardcoded.
I know must be easy the solution but this problem is drives me crazy...How can I resolve this?
Thanks in advance.
My Uri is hardcoded
That is not possible. You do not have rights to such a document, even if the Uri is valid (which it won't be, since the DocumentsProvider did not do any work on its side to grant it). Beyond that, the user may not have a document at the location that you hard-coded.
How can I resolve this?
Use ACTION_OPEN_DOCUMENT and allow the user to choose the document to remove.
Or, use filesystem locations that you can read and write across OS versions, mostly those defined on Context: getFilesDir(), getCacheDir(), getExternalFilesDir(), getExternalCacheDir(), etc. In this case, you will not need to work with Uri values.

How to List all Internal Storage Folders in Android Q (API Level 29)?

I am new in programming and want to make a file manager in android studio. I am facing problems in listing all device folders in API level 29 after getExteralStorageDirectory was deprecated.
According to the documentation, you will have to use ACTION_OPEN_DOCUMENT_TREE. This will provide you with the URI of selected directory, once you have the URI then you can access all the children of that directory. From docs
Grant access to a directory's contents
File management and media-creation apps typically manage groups of
files in a directory hierarchy. To provide this capability in your
app, use the ACTION_OPEN_DOCUMENT_TREE intent action, which allows the
user to grant access to an entire directory tree. Your app can then
access any file in the selected directory and any of its
sub-directories.
There is also ActionOpenDocumentTree sample app on github which shows how to implement this feature.

How can we download file(pdf) in android studio from firebase such that it doesn't appear in phone's internal storage?

I am developing an application where I need to download pdf files from firebase storage and store it inside the app(the one I am developing) and these files shouldn't be accessible to user outside my app. I had developed using Firebase code for downloading but it is downloading in the download folder of mobile even after changing the destination directory.
Nowadays there are two kinds of storage in an android device: Internal and external.
According to android docs:
Internal storage:
It's always available.
Files saved here are accessible by only your app.
When the user uninstalls your app, the system removes all your app's files from internal storage.
External storage:
It's world-readable, so files saved here may be read outside of your control.
It's not always available, because the user can mount the external storage as USB storage and in some cases remove it from the device.
When the user uninstalls your app, the system removes your app's files from here only if you save them in the directory from getExternalFilesDir().
External storage is the best place for files that don't require access restrictions and for files that you want to share with other apps or allow the user to access with a computer.
Internal storage is best when you want to be sure that neither the user nor other apps can access your files.
To get path of internal storage of your app:
getFilesDir()
This will give you a File representing the directory on the file system that's uniquely associated with your app.
Hope it helps!
Source: Save files on device storage
EDIT:
If you want the file downloaded from firebase storage to be only visible to your app, you should move the file from downloads to internal storage and then delete the file from downloads

Unable to read file using FileProvider

I have multiple apps that take photos and store them on external storage.
I want to upload the photos along with some metadata to a web application running on my companies server.
I am able to write data and file URI to a database using a ContentProvider.
I have written a SyncAdapter to upload the files via HTTP-POST, but I am stuck because in this SyncAdapter I cannot get permission to read the files.
My big question is: Can I use a FileProvider to overcome this issue?
I am NOT storing the files in the ContentProvider using an intent.
I have tried to set permissions on URL, it failed.
I Desperation I tried to export the FileProvider, which was not allowed.
I want to be able to open an input-stream of the file in another app than the one storing the file without having to start the transfer using an Intent.

How can I read a file in Internal Storage without declaring the permission?

I'm writing an app that allows users to import their own data (via .zip's, .png's etc.) from an external location such as their downloads folder.
My app is correctly getting the file path from the URI, however I do not wish to require the WRITE_EXTERNAL_STORAGE permission in my app, which I need in order to read the file the user is providing me. I feel like Android should allow my app read permission to this file, since the user selected it.
Is there a way to have Android copy this file to a temporary location where I can read it, so that I do not need to ask the user for this permission?
If you don't want the permission, then there is a way for Android4.4 and above. Let the user import the data into the programdirectory, see also:
Starting in Android 4.4, the owner, group and modes of files on
external storage devices are now synthesized based on directory
structure. This enables apps to manage their package-specific
directories on external storage without requiring they hold the broad
WRITE_EXTERNAL_STORAGE permission. For example, the app with package
name com.example.foo can now freely access
Android/data/com.example.foo/ on external storage devices with no
permissions. These synthesized permissions are accomplished by
wrapping raw storage devices in a FUSE daemon.
Taken from this page -> https://source.android.com/devices/storage/index.html

Categories