From 2dd62ab3c6dfff76390e4aed52d59b318794dff3 Mon Sep 17 00:00:00 2001 From: tibbi Date: Thu, 29 Mar 2018 16:35:57 +0200 Subject: [PATCH] change get_content intent to an open_document one with persistent read uri perm --- .../com/simplemobiletools/clock/activities/MainActivity.kt | 6 ++++++ .../clock/dialogs/SelectAlarmSoundDialog.kt | 3 ++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/app/src/main/kotlin/com/simplemobiletools/clock/activities/MainActivity.kt b/app/src/main/kotlin/com/simplemobiletools/clock/activities/MainActivity.kt index 5c1440af..63f8eb63 100644 --- a/app/src/main/kotlin/com/simplemobiletools/clock/activities/MainActivity.kt +++ b/app/src/main/kotlin/com/simplemobiletools/clock/activities/MainActivity.kt @@ -1,8 +1,10 @@ package com.simplemobiletools.clock.activities +import android.annotation.TargetApi import android.content.Intent import android.graphics.drawable.ColorDrawable import android.net.Uri +import android.os.Build import android.os.Bundle import android.view.Menu import android.view.MenuItem @@ -128,6 +130,7 @@ class MainActivity : SimpleActivity() { } } + @TargetApi(Build.VERSION_CODES.KITKAT) private fun storeNewAlarmSound(uri: Uri) { var filename = getFilenameFromUri(uri) if (filename.isEmpty()) { @@ -139,6 +142,9 @@ class MainActivity : SimpleActivity() { val newAlarmSoundId = (yourAlarmSounds.maxBy { it.id }?.id ?: YOUR_ALARM_SOUNDS_MIN_ID) + 1 yourAlarmSounds.add(AlarmSound(newAlarmSoundId, filename, uri.toString())) config.yourAlarmSounds = Gson().toJson(yourAlarmSounds) + + val takeFlags = Intent.FLAG_GRANT_READ_URI_PERMISSION + contentResolver.takePersistableUriPermission(uri, takeFlags) } private fun initFragments() { diff --git a/app/src/main/kotlin/com/simplemobiletools/clock/dialogs/SelectAlarmSoundDialog.kt b/app/src/main/kotlin/com/simplemobiletools/clock/dialogs/SelectAlarmSoundDialog.kt index 722b2e82..f6a85c65 100644 --- a/app/src/main/kotlin/com/simplemobiletools/clock/dialogs/SelectAlarmSoundDialog.kt +++ b/app/src/main/kotlin/com/simplemobiletools/clock/dialogs/SelectAlarmSoundDialog.kt @@ -83,9 +83,10 @@ class SelectAlarmSoundDialog(val activity: SimpleActivity, val currentUri: Strin private fun alarmClicked(alarmSound: AlarmSound) { if (alarmSound.id == ADD_NEW_SOUND_ID) { - Intent(Intent.ACTION_GET_CONTENT).apply { + Intent(Intent.ACTION_OPEN_DOCUMENT).apply { type = "audio/*" activity.startActivityForResult(this, PICK_AUDIO_FILE_INTENT_ID) + flags = flags or Intent.FLAG_GRANT_PERSISTABLE_URI_PERMISSION } dialog.dismiss() } else {