I copy a file from USB to my SamSung S7 tablet using My Files app shipped with my tablet. I can find this file under /data using My Files app.
I believe this file is stored in the shared external storage. As pointed in
https://developer.android.com/training/data-storage
I need Android Storage Access Framework to access this file.
I want to access this file with my own app and I need to know the URL. What's the URL look like?
Thanks.
YL
A file URL looks like this in Android and you can use this type of URL to access files:
file:///path/to/foo.txt
file:// is used to refer to URL pointing to a world-readable file.
You can get path to directory from one of these getExternalFilesDir() or getExternalCacheDir() or getExternalMediaDirs(). Hence, getExternalStorageDirectory is deprecated and no longer recommended for use. (Read more here)
Lastly, make sure you have made permission to access: WRITE_EXTERNAL_STORAGE and READ_EXTERNAL_STORAGE
Let me know if you have any questions. Thanks.
Related
As we know from android 11 Write external storage permission will not work, we cant access the other directories of root path of external storage, But my question is what about the File Manager App, if my app is File Manager than how do I Manage all file operation as like before. for example, new file or folder creation, here we can not get root path access of external storage, so how to manage File Manager operation, I read in the developer site and somewhere their is option to handle that particular apps, and Google also give some way to manage that app, but how I cant find some solution, If anyone know please help me out from this.
As we know from android 11 Write external storage permission will not work, we cant access the other directories of root path of external storage,
Requesting write external storage makes no sense as it is implicitly granted to your app already.
You can access all paths from getExternalStorageDirectory() and getExternalStoragePublicDirectory().
And create subdirs and files in the getExternalStoragePublicDirectory()'s
It seems that getExternalStoragePublicDirectory() is now deprecated, so I need an alternative.
Say I have file the foo.png in my app's internal storage. I can easily access this file with
val foo = File(context.filesDir, "foo.png")
My problem is that I want to move this file to the user's Downloads directory, so that they can see it on their phone.
This answer uses DownloadManager. Unfortunately this is an image I generate myself, not download from somewhere.
You have two options.
Use Storage Acces Framework to let the user choose the Download directory .
Use MediaStore to insert file to Download directory.
I'm working with one of the many Android FFmpeg libraries on GitHub, which each involve an NDK wrapper around a C binary. I'm trying to give other apps access to the video file I have edited with FFmpeg (and saved in External Storage), but at least on Android 6.0, the new permissions system prevents them from being able to access the shared file unless they themselves have the External Storage permission granted. The solution here would be to use content providers to open up a directory for other apps to access. However...
My FFmpeg binary is contained within the app's data directory, but it fails when I try to access or modify a video file saved there. As mentioned above, it has no problem accessing external storage.
Is there a way to give FFmpeg access to my app's data directory, giving it read and write permissions? Would naming the library with the same package name do the trick?
Any ideas? Thanks for any advice!
I would like to send a file by email. The app writes a csv file, and then shares this file via the usual ACTION_SEND Intent.
For this to work, the file must be readable by other apps (the email app).
I have tried getExternalStorageDirectory() but it doesn't work. /sdcard works but I feel it is clumsy to use a path like that
What's the best alternative ?
It returns null
Perhaps you are running on an emulator for which you did not configure external storage (erroneously referred to as "SD card" in the AVD Manager). I can think of no reason for getExternalStorageDirectory() to return null on a production device.
What's the best alternative ?
Use FileProvider to share the file from your app's internal storage.
I'm writing an Android app which uses wi-fi, so I can't easily debug to emulator (no wi-fi support... ;-), so I go with my real device (a Samsung Galaxy S).
I would like to be able to read data files my app writes, to debug and test.
If I use, say:
new File(getFilesDir(), "myfile.xml");
I get my data file written to /data/data/MYPACKAGE/files/, but that directory is non accessible via adb (nor via Eclipse's DDMS).
My device is not rooted (and I'd prefer to avoid rooting it, if possible... ;-)
Where should I write my data file to?
It probably makes sense to put the files on the sdcard during development, formally you should call getExternalStorageDirectory() to find it and of course will need external storage permission.
Alternatively, you could give public access to your private files in the debug version; just don't forget to turn that off before you ship (as a certain Internet telephony company reportedly did). However, this will not make the private files browsable as the intervening directories are not, you would only be able to adb pull them via their exact path name.
A third choice would be to leave the data internal and private, but have a debug function to copy it over to the sdcard for analysis. You could even do this in a separate .apk establishing a shared user id with the first, meaning no changes at all to your application.
Simply use external storage!
You can write to your SDcard. You should use getExternalStorageDirectory() to get your SDcard's path. You will have to include the <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> in your Manifest to do that.
The answer differs depending on your API level. Review the section in the documentation on external storage to get the answer for this.
http://developer.android.com/guide/topics/data/data-storage.html#filesExternal
For a somewhat generic answer, the sdcard directory that you should be storing files in is the directory returned from getExternalStorageDirectory() (which should be the root of your sdcard or possibly internal expanded storage as with my Captivate), with subdirectories of /Android/data/your.package.name/files
Oh yes, and as another poster mentioned, don't forget the WRITE_EXTERNAL_STORAGE permission in your manifest.