I have a problem. I am trying to change names of my app's directories for users data. I change it in a code and delete it from phone to check if the app create new ones with right names. And then troubles begin. Directories are created but when I try to open directory in windows explorer, It is seen as a file. mkdir()
return true
for each directory.
When I check Environment.getExternalStorageDirectory().canWrite()
it return true
too. My gradle
configuration
compileSdkVersion 23
minSdkVersion 23
targetSdkVersion 23
(I want to downgrade to minSdkVersion 21). In manifest I have:
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
Some code (updated):
File appDir = new File (Environment.getExternalStorageDirectory().getAbsolutePath()+"/Trainer app/");
File modelsDir = new File(appDir.getAbsolutePath()+"/Modele/");
File pdfDir = new File(appDir.getAbsolutePath()+"/Ostatnio wygenerowany trening/");
boolean result;
if(!appDir.exists()){
Log.wtf("StorageState",""+Environment.getExternalStorageState()+" Write: "+Environment.getExternalStorageDirectory().canWrite());
Log.wtf("TEST DIR","Create appDir "+result+" is dir: "+appDir.isDirectory());
Log.wtf("TEST DIR","Create appDir "+result);
MediaScannerConnection.scanFile(this, new String[]{appDir.toString()}, null, null);
}
//if(appDir.exists()&&!modelsDir.exists()){
if(!modelsDir.exists()){
//Log.wtf("MODELDIR", "" + modelsDir.mkdir() + " Path: " + modelsDir.getAbsolutePath());
result=modelsDir.mkdirs();
Log.wtf("TEST DIR", "Create modelDir "+result+" is dir: "+modelsDir.isDirectory());
MediaScannerConnection.scanFile(this, new String[]{modelsDir.toString()}, null, null);
}
//if(appDir.exists()&&!pdfDir.exists()){
if(!pdfDir.exists()){
//Log.wtf("PDFDIR", "" + pdfDir.mkdir() + " Path: " + pdfDir.getAbsolutePath());
result=pdfDir.mkdirs();
Log.wtf("TEST DIR","Create pdfDir "+result+" is dir: "+pdfDir.isDirectory());
MediaScannerConnection.scanFile(this, new String[]{pdfDir.toString()}, null, null);
}
UPDATE: now I have no right to write on external storage. When I change minSdk
to 21 and targetSdk
to 22 I have rights but I still can't create directories even using your tips