mirror of
https://github.com/SimpleMobileTools/Simple-Voice-Recorder.git
synced 2025-02-24 23:47:48 +01:00
fix file renaming on Android 11+
This commit is contained in:
parent
c8451ae9b8
commit
fd9d65c51b
@ -8,9 +8,12 @@ import com.simplemobiletools.commons.extensions.*
|
|||||||
import com.simplemobiletools.commons.helpers.ensureBackgroundThread
|
import com.simplemobiletools.commons.helpers.ensureBackgroundThread
|
||||||
import com.simplemobiletools.commons.helpers.isQPlus
|
import com.simplemobiletools.commons.helpers.isQPlus
|
||||||
import com.simplemobiletools.voicerecorder.R
|
import com.simplemobiletools.voicerecorder.R
|
||||||
|
import com.simplemobiletools.voicerecorder.extensions.config
|
||||||
import com.simplemobiletools.voicerecorder.helpers.getAudioFileContentUri
|
import com.simplemobiletools.voicerecorder.helpers.getAudioFileContentUri
|
||||||
|
import com.simplemobiletools.voicerecorder.models.Events
|
||||||
import com.simplemobiletools.voicerecorder.models.Recording
|
import com.simplemobiletools.voicerecorder.models.Recording
|
||||||
import kotlinx.android.synthetic.main.dialog_rename_recording.view.*
|
import kotlinx.android.synthetic.main.dialog_rename_recording.view.*
|
||||||
|
import org.greenrobot.eventbus.EventBus
|
||||||
import java.io.File
|
import java.io.File
|
||||||
|
|
||||||
class RenameRecordingDialog(val activity: BaseSimpleActivity, val recording: Recording, val callback: () -> Unit) {
|
class RenameRecordingDialog(val activity: BaseSimpleActivity, val recording: Recording, val callback: () -> Unit) {
|
||||||
@ -63,12 +66,24 @@ class RenameRecordingDialog(val activity: BaseSimpleActivity, val recording: Rec
|
|||||||
put(Media.DISPLAY_NAME, newDisplayName)
|
put(Media.DISPLAY_NAME, newDisplayName)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// if the old way of renaming fails, try the new SDK 30 one on Android 11+
|
||||||
try {
|
try {
|
||||||
activity.contentResolver.update(getAudioFileContentUri(recording.id.toLong()), values, null, null)
|
activity.contentResolver.update(getAudioFileContentUri(recording.id.toLong()), values, null, null)
|
||||||
|
} catch (e: SecurityException) {
|
||||||
|
try {
|
||||||
|
val path = "${activity.config.saveRecordingsFolder}/${recording.title}"
|
||||||
|
val newPath = "${path.getParentPath()}/$newDisplayName"
|
||||||
|
activity.handleSAFDialogSdk30(path) {
|
||||||
|
val success = activity.renameDocumentSdk30(path, newPath)
|
||||||
|
if (success) {
|
||||||
|
EventBus.getDefault().post(Events.RecordingCompleted())
|
||||||
|
}
|
||||||
|
}
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
activity.showErrorToast(e)
|
activity.showErrorToast(e)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private fun updateLegacyFilename(recording: Recording, newTitle: String) {
|
private fun updateLegacyFilename(recording: Recording, newTitle: String) {
|
||||||
val oldExtension = recording.title.getFilenameExtension()
|
val oldExtension = recording.title.getFilenameExtension()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user