Android как получить путь External
Я пытаюсь создать папку во внешнем хранилище и потом получить путь к нему в виде переменной String. В результате папка не создается хотя в манифесте доступ прописан.
// получаем путь к External
File FPath = Environment.getExternalStorageDirectory();
FPath = new File(FPath.getAbsolutePath() + "/" + "Word");
FPath.mkdir();
// формируем объект File, который содержит путь к файлу
String filePath =
Environment.getExternalStorageDirectory().toString()+"/Word";
Файл манифеста
<?xml version="1.0" encoding="utf-8"?>
<manifest
xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.lesson5">
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:roundIcon="@mipmap/ic_launcher_round"
android:supportsRtl="true"
android:theme="@style/AppTheme">
<activity android:name=".MainActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
</application>
<uses-permission
android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission
android:name="android.permission.READ_EXTERNAL_STORAGE"/>
</manifest>
Ответы (1 шт):
Автор решения: Tony
→ Ссылка
success = (new File("../potentially/long/pathname/without/all/dirs")).mkdirs();
if (!success) {
// Directory creation failed
}