This question is duplicate or triplicate, but I can't create a folder! I've read other questions on this site. I have added the permission in the manifest.xml:
<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.val.scemo">
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity
android:name=".MainActivity"
android:label="@string/app_name"
android:theme="@style/AppTheme.NoActionBar">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
</manifest>`
My code is this (I tried everything, I have copied the code from the answers on this site):
File logFile = new File(LOG_PATH);
boolean a = false;
a = logFile.getParentFile().mkdirs();
Log.d("Creare: ", "Directory creata? " + a);
///////////////////////////////////////////////////
File folder = new File(Environment.getExternalStorageDirectory() + File.separator + "TollCulator");
boolean success = true;
if (!folder.exists()) {
Log.d("Creare: ", "Riprovo ");
success = folder.mkdir();
Log.d("Creare: ", "Fatto ");
}
if (success) {
Log.d("Creare: ", "Cartella creata!1 ");
// Do something on success
} else {
Log.d("Creare: ", "FAIL1 ");
// Do something else on failure
}
/////////////////////////////////////////////////////
folder = new File(Environment.getExternalStorageDirectory().getAbsolutePath() + "/Example");
boolean success1 = true;
if (!folder.exists()) {
success1 = folder.mkdirs();
}
if (success1) {
Toast.makeText(getApplicationContext(), "Success", Toast.LENGTH_LONG).show();
Log.d("Creare: ", "Cartella creata!2 ");
} else {
Toast.makeText(getApplicationContext(), "Failure", Toast.LENGTH_LONG).show();
Log.d("Creare: ", "FAIL2 ");
}
All fails. Where am I wrong? Sorry for my English.