问题描述
我想在 /storage/emulated/0/ 中创建一个目录并在那里保存一个文件。由于“getExternalStorageDir()”和“getExternalPublicStorageDir()”已折旧,我不知道如何实现它。 我已经完成了大部分问题和答案,但它们都已过时/开放。 我想要的只是一种访问“storage/emulated/0/”路径的方法。
<table class="table table-bordered table-responsive-sm table-hover">
<thead>
<tr>
<th>Date</th>
<th>TimeSlot</th>
<th>Room</th>
<th>Attendees</th>
<th>update</th>
<th>delete</th>
</tr>
</thead>
<tbody>
<tr class="table">
<td class="table">...</td>
<td class="table">...</td>
<td class="table">...</td>
<td class="table">...</td>
<td class="table" style="display: none">...</td>
<td class="table" style="display: none">...</td>
<td class="table" style="display: none">...</td>
<td class="table" style="display: none">...</td>
<td class="table command">
<a onclick="onUpdate()" style="color: #007bff; cursor: pointer"> <i class="fa fa-pencil-square-o" aria-hidden="true"></i></a>
</td>
<td class="table command">
<a onclick="onDelete()" style="color: #007bff; cursor: pointer"> <i class="fa fa-trash" aria-hidden="true"></i></a>
</td>
</tr>
</tbody>
</table>
以上代码在“Android/data/com.xxx.xxx/”中创建了一个文件夹
解决方法
轻松使用 MediaStore
。
binding.createFolderButton.setOnClickListener {
val values = ContentValues()
values.put(MediaStore.MediaColumns.RELATIVE_PATH,"${Environment.DIRECTORY_DOCUMENTS}/myFolder/") //folder name
contentResolver.insert(MediaStore.Files.getContentUri("external"),values)
Toast.makeText(this,"\"myFolder\" created",Toast.LENGTH_SHORT).show()
}