I am developing an android application using Android Studio and Java.
I need to create a directory and manipulate some files. But above all, I need this directory to be visible to the user when they connect the phone with a USB cable.
I am using the "external" memory of the phone. Not the internal one. Not even removable.
I am using Bookan code (Can't create folder on external storage on android) to create the directory.
private void createFolder () {
if (isStoragePermissionGranted ()) {
File folder = new File (Environment.getExternalStorageDirectory () + File.separator + "NewFolderCreated");
if (! folder.exists ()) {
folder.mkdir ();
}
}
public boolean isStoragePermissionGranted () {
if (Build.VERSION.SDK_INT> = 23) {
if (checkSelfPermission (android.Manifest.permission.WRITE_EXTERNAL_STORAGE)
== PackageManager.PERMISSION_GRANTED) {
return true;
} else {
ActivityCompat.requestPermissions (this,
new String [] {Manifest.permission.WRITE_EXTERNAL_STORAGE}, 1);
return false;
}
}
else {// permission is automatically granted on sdk <23 upon installation
return true;
}
}
In the manifest file, permissions are present.
<uses-permission android: name = "android.permission.WRITE_EXTERNAL_STORAGE" />
Although WRITE's permission implies reading and writing, I have made both explicit.
When I have console output displayed for the path created, I have the answer:
/storage/emulated/0/NewFolderCreated
However, when accessing the directory through Windows Explorer, "NewFolderCreated" is neither a folder nor a file. Get that unassociated item icon in windows. You can see that windows does not know that it is a directory.
What am I doing wrong?
If I try to access the directory through android studio's file explorer, I have the permission error, which I can't solve either.
ls: /storage/emulated/: Perm
EDIT1: Added a screenshot