Unable to read file using FileProvider - java

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.

Related

Storage on android 11

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)

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

Store files in google drive from Google App Engine

All,
I have a google application engine (java) that requires to store some images. I tried using Blobs and storing them in datastore but as you know there is a size limit on data that can be stored in datastore.
So as result I'm storing the images on a different server and store the path in my datastore and all works fine.
Now I'm thinking on using a google drive folder instead of using a server to upload the files to the drive and using the share link to display them later.
I've seen https://developers.google.com/drive/web/quickstart/java and got it to work fine. When I try to use it in my application however obviously this won't work as the code is assuming a credential for a local user.
I created a service key on my application and want to change the sample code above to use it but I'm not sure if that's the correct approach.
Tried searching for samples but can't find anyone that takes the same approach. Is there a working sample that shows how to authenticate an application not a user and let's say store a file in google drive?
I've also seen https://developers.google.com/drive/web/examples/ please note what I want is to store files in my google drive and not the user's google drive. So if user A and user B come to my app, they shouldn't have to authorize my application and should both be able to upload a file to my google drive.
I don't know if this can be done directly from their browser or I have to move the file to my application (appspot) and then push it to google drive.
Thanks

hosting the database file on any cloud service

I have an android application, which wants the user to login each time he runs the app. So, the login procedure is simple, using the sqlite dabase file i'm using. I've copied the file in assets folder and doing the necessary modifications. But, the database file is of no use unless it is on the server. I don't have any server so i'm thinkin of keeping the database file on dropbox, google drive etc and then read or update that file as per user commands. The question is how to do that? I was searching the web for it, and found that the only way is downloading the db file modifying it and the uploading it back. Can anyone give me an example??
Doing that isn't possible unless you have a server.
Because, if you are using dropbox, first you'll have to make your file public in order to download it (Not recommended at all. Compromises security). Then you can use the url to download the file. But you won't be able to upload it back (Unless you are able to login to dropbox through your Android code).
Instead if you a web server with MySQL n PHP, you can easily send POST requests to your server.

Writing file from PHP page android

In my project a compressed file is displayed on a php in bytes.
I am trying to find a way to read the php page, decompress the file using GZIP, and write it out to the assets folder.
The file that I am reading in has to be placed in the data/data/package/database file.
I have a class that reads a file from the assets folder and places the file into data/data/package/database.
Is it possible to write to the assets folder during runtime? If not is there a better way to do this?
if the PHP script is running on a server, your Android app will need to make an HTTP request to retrieve the content. of course then it has to store it somewhere. the SQLite database is a good option, but you could also store content in files on the SD card.
there are a couple ways to do the HTTP connection part of it, and they're written up on the Android Dev Blog. Myself, I prefer the HttpURLConnection.

Categories