Issue
This is my directory structure on my Android sdcard
sdcard/alQuranData/Reader1/Surah
Here is my code to make Directories
File SDCardRoot = new File(Environment.getExternalStorageDirectory().toString() + "alQuranData/Reader1/Surah");
Toast.makeText(getApplicationContext(), SDCardRoot.toString(), Toast.LENGTH_LONG).show();
if (!SDCardRoot.exists()) {
Log.d("DIRECTORY CHECK", "Directory doesnt exist creating directory");
SDCardRoot.mkdir();
}
Now alQuranData
is already created in my sdcard
root. If i only create Reader1 directory than it works fine, but when is add Reader1/Surah
than it did not create.
I also tried mkdirs()
but it doesn't work.
Solution
Are you getting any error or exception. Please try to check the return value of mkdirs()
method call. ALso try the following code:
File SDCardRoot = new File(Environment.getExternalStorageDirectory().toString() + "/alQuranData/Reader1/Surah");
Toast.makeText(getApplicationContext(), SDCardRoot.toString(), Toast.LENGTH_LONG).show();
if (!SDCardRoot.exists()) {
Log.d("DIRECTORY CHECK", "Directory doesnt exist creating directory");
SDCardRoot.mkdirs();
}
Please also check that you have added following permission in manifest file:
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
I just tested the following code and it is working on my end:
File SDCardRoot = new File(Environment.getExternalStorageDirectory()
.toString() + "/alQuranData/Reader1/Surah");
Toast.makeText(getApplicationContext(), SDCardRoot.toString(),
Toast.LENGTH_LONG).show();
if (!SDCardRoot.exists()) {
Log.d("DIRECTORY CHECK",
"Directory doesnt exist creating directory "
+ Environment.getExternalStorageDirectory()
.toString());
boolean outcome = SDCardRoot.mkdirs();
Log.d("DIRECTORY CHECK",
"outcome for " + SDCardRoot.getAbsolutePath() + " "
+ outcome);
}
I have added alQaranData folder manually as mentioned in your post and added the permission and it start working at my end. Please check this code.
Answered By - Praful Bhatnagar
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.