Android KitKat sdcard write permission

社会主义新天地 提交于 2019-12-25 02:55:17

问题


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 APIs 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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!