简体   繁体   中英

Creating directory in External storage

I'm trying to solve the problem with creating directory on Android device. I noticed that some third party apps create catalog on internal directory /storage/emulated/0/Android/data which. How It can achieved? Here's my piece of code, but It doesn't work :

 if(FileUtils.isExternalStorageAvailable() && FileUtils.isExternalWritable()){
                File path = new File(Environment.getExternalStorageDirectory() +"/Android/data/reports");
                Log.d("DEBUG", Environment.getExternalStorageDirectory() +"/Android/data/reports");
                if(path.mkdirs()){
                    Toast.makeText(getActivity(), "catalog created", Toast.LENGTH_LONG).show();
                }
            }

Thanks For Help, Regards

You may be being blocked because Android/data/ on external storage is used by Android for getExternalFilesDir() and kin. If you want a directory in Android/data/ , just use getExternalFilesDir() (bonus: no permission required on API Level 19+).

Beyond that, make sure that you are handling runtime permissions .

And, eventually, you will want to add code to allow users to see files that you put in your directory .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM