I have updated my app to API level 29 so it broke my image picking mechanism. Eariler everything was working fine. Now when I searched over forums/stackoverflow I came to know that I have to migrate to scoped storage framework in order to make it work. I found 2 things so far
opt out of scoped storage
Read the stream and write into cache directory so that my app can access it.
My question is that is it mandatory to copy the file for using it. If yes I'm afriad to use this approach as it will consume lot of time because my app uses large videos which we upload to server.
Is it possible to use this framework to just read the URI of image/video without copying to cache directory ? Did anyone worked on it ?
for reference I followed these articles
https://developer.android.com/guide/topics/providers/document-provider
https://medium.com/#sriramaripirala/android-10-open-failed-eacces-permission-denied-da8b630a89df
https://issuetracker.google.com/issues/130494105
Related
I am trying to write an Android App in Delphi 10.4 (primarily for AndroidTV) using Delphi which can read or write files from/to USB mass storage. I can see the files using FileManager App, but have failed to see them with my App. I found a library on GitHub (Libaums) which would appear to do all I want and much more, but is written in a mixture of Kotlin, Java, and C, which would appear to be very difficult to integrate with Delphi.
Edit: The paths I have tried include: GetDataDirectory(), GetRootDirectory(), GetExternalStorageDirectory(),GetSysExternalStorageDirectory(), GetExternalStoragePublicDirectory(), /mnt/usb001, /mnt/usb002, /mnt/androidwritable, /mnt/user.
The device in mind currently uses SDK 28, but I would like a solution that would still work on later versions.
All my attempts to get file paths report non-existent, which I take to mean I have a permissions problem. Can anyone:
(1) Advise which file path to request?
(2) How to obtain the relevant permissions?
TIA
I am trying to upgrade my targetSdkVersion to 30. A download manager in the legacy code, expects a File object and creates a file at the file path. I was creating the file using this syntax : File("${Environment.getExternalStorageDirectory()}/$directoryPath").
Since the introduction of Scoped Storage, i can no longer do so.
According to official document document:
I can either create the file in my app directory
Or I can add the file to Shared Storage (which is the preferred use case for me)
Method 2 suggest use of Storage Access Framework. But for that i will have to replace the Download Manager. And that will be huge task and lot for refactoring.
However, i came across this answer on SO
which suggests using File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS).toString()+File.separator+directoryPath) and strangely, it works on both android 10 and 11.
Wondering how it works even though it is deprecated, and is it the right way of doing things?
The application I'm currently working on requires a manual setup (entering some information) on device provisioning. This information needs to be written to a file that should not be deleted when the application is uninstall or the application data is wiped (user support requirement, as they can direct users to do this in some cases)
There was a very similar old question, but the answer is now deprecated and no up-to-date answer has been posted
Keep files after uninstallation of android app
So the question is, given the deprecation of Environment.getExternalStorageDirectory() on Android 10, how do we programmatically write/read a file that will not be deleted when the application is uninstalled or the data is wiped?
For what is worth, we can not rely on app auto backup, as the users don't have google accounts configured.
Thanks
To summarize while targetting 30.
For Android 10 device: Request legacy external storage to get external storage access as usual.
And Googles step back for Android 11 devices: use directories like Download, Pictures, Movies, Documents, DCIM and so on. Read and write access for all. Android OS is very picky to use the right extensions for files to be created in those folders.
I have an Android application that generates some data (simple text file) that I would like to transfer to my PC for further processing. My understanding is that my storage options for a place to save such a file are a) internal storage or b) external storage. My device is a rooted Nexus 7 running Marshmallow, and I can't get either option to work.
With internal storage I'm able to write the file but then it's nowhere to be found using ADB or Eclipse DDMS. With external storage I'm getting FileNotFoundExceptions which I'm guessing are due to new complicated permissions, so none of Android saving file to external storage is working.
Is this possible and, if so, is there an easy way to do it?
What is your targetSdkVersion? If you target 22 and below, the new permission policy won't take effect.
It is possible to write a text file in Android and read the same in your PC using external-storage.
This app does the same.
You can find a simple example here.
If this does not work for you, kindly share your code-snippet that writes the file.
We have built an android app that lets users download content from an http endpoint. The downloaded file is stored via Context.getExternalFilesDir(null) if the external drive is writable otherwise we use Context.getFilesDir() to store internally. In either case, we store the absolute path to a database (which could point to an internal or external file path) so we know how and where to find it later.
We've received a number of emails to our tech support saying that after they close and reopen the app that the files are gone. The people emailing with the problem don't have exact steps for reproducing but that has been their experience. No one on our team has been able to reproduce the bug, but it gets reported consistently.
The same people reporting the problem say that they are able to use the files when they download them. The problem is that when they come back to the app later they have to re-download them.
Am I missing something that the framework is maybe doing to delete the files on certain devices/versions?
I think some might jump to the conclusion that it's an external path issue. Meaning it gets saved there, and when they want to access it later the drive isn't mounted any more and therefore the file is "gone". We have a setting the user can check to force downloads to be saved via the internal method (which tech support has them try) Context.getFilesDir() so I don't believe that would be an issue.
I know this is quite vague but I've been getting nowhere now for quite some time. Perhaps some thoughts on storage in general would be helpful. How have you handled storing internal and external files?