Below is the code that I'm using
String root = Environment.getExternalStorageDirectory().getAbsolutePath().toString();
File filepathname = new File(root+"/newfolder");
if(filepathname.mkdir())
Toast.makeText(this,"directory created", Toast.LENGTH_SHORT).show();
else
Toast.makeText(this,"directory not created", Toast.LENGTH_SHORT).show();
I tried this code in Moto E (running Lollipop) and Nexus 5 (running marshmallow). Folder gets created in Moto but not in Nexus 5.
I have been able to create folder in Nexus 5 before upgrading to Marshmallow.
Is this a known problem in android M? Is there a work around? Or can anyone spot any problem in the code.
Notes:
The above mentioned code is in the onCreate()
of my launcher activity,
The below permission is also there in the manifest file:
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
"newfolder" does not exist already.
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…