问题
In android KitKat there are some limitations for writing to SDcard.
So my question: Is it always permitted to write to Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES)
even in KitKat?
回答1:
Is it always permitted to write to Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES) even in KitKat?
If your app has requested the WRITE_EXTERNAL_STORAGE
permission, then yes, as getExternalStoragePublicDirectory()
points to external storage, which is not removable storage ("SDCard") on the vast majority of devices.
回答2:
You first need to understand concepts of Android Storage.
Then you will understand that Environment.getExternalStorageDirectory()
or something like that is about primary external storage
. And it has nothing to do with Android API
s whether it is younger or older than KitKat
.
回答3:
To get the internal SD card you can use
String extStore = System.getenv("EXTERNAL_STORAGE");
File f_exts = new File(extStore);
To get the external SD card you can use
String secStore = System.getenv("SECONDARY_STORAGE");
File f_secs = new File(secStore);
On running the code
extStore = "/storage/emulated/legacy"
secStore = "/storage/extSdCarcd"
works perfectly!
refer following Link , I think ur question has been answered already check this...
Android Open External Storage directory(sdcard) for storing file
来源:https://stackoverflow.com/questions/29513004/android-kitkat-sdcard-write-permission