誰かがこれを重複としてマークする前に、私はmkdirs()
SO の方法について多くの質問をしましたが、どれもうまくいかなかったので、この問題には質問に値する特別なケースがあると信じています.
を使用してみmkdir()
ましたが、ディレクトリのインスタンス化を次のように変更しFile
ました
new File(Environment.getExternalStorageDirectory())
new File(Environment.getExternalStorageDirectory().getAbsolutePath())
new File(Environment.getExternalStorageDirectory(), "Directory")
new File(Environment.getExternalStorageDirectory().getAbsolutePath(), "Directory")
new File(Environment.getExternalStorageDirectory().toString + "/Directory")
そして何も機能しません。
注:WRITE_EXTERNAL_STORAGE
マニフェストにも許可があります。
ここに私のコードスニペットがあります:
File rootDirectory = new File(Environment.getExternalStorageDirectory(), getActivity().getPackageName());
File directory = new File(rootDirectory, "Directory");
if (!directory.exists()) {
if(directory.mkdirs()){
Log.d("log", "exists");
} else {
Log.d("log", "not exists");
}
}