use a different audio file pick intent on 4.3- devices
This commit is contained in:
parent
2dd62ab3c6
commit
cbe2617624
|
@ -1,10 +1,8 @@
|
||||||
package com.simplemobiletools.clock.activities
|
package com.simplemobiletools.clock.activities
|
||||||
|
|
||||||
import android.annotation.TargetApi
|
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
import android.graphics.drawable.ColorDrawable
|
import android.graphics.drawable.ColorDrawable
|
||||||
import android.net.Uri
|
import android.net.Uri
|
||||||
import android.os.Build
|
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.view.Menu
|
import android.view.Menu
|
||||||
import android.view.MenuItem
|
import android.view.MenuItem
|
||||||
|
@ -23,6 +21,7 @@ import com.simplemobiletools.clock.models.AlarmSound
|
||||||
import com.simplemobiletools.commons.extensions.*
|
import com.simplemobiletools.commons.extensions.*
|
||||||
import com.simplemobiletools.commons.helpers.LICENSE_NUMBER_PICKER
|
import com.simplemobiletools.commons.helpers.LICENSE_NUMBER_PICKER
|
||||||
import com.simplemobiletools.commons.helpers.LICENSE_STETHO
|
import com.simplemobiletools.commons.helpers.LICENSE_STETHO
|
||||||
|
import com.simplemobiletools.commons.helpers.isKitkatPlus
|
||||||
import com.simplemobiletools.commons.models.FAQItem
|
import com.simplemobiletools.commons.models.FAQItem
|
||||||
import kotlinx.android.synthetic.main.activity_main.*
|
import kotlinx.android.synthetic.main.activity_main.*
|
||||||
import java.util.*
|
import java.util.*
|
||||||
|
@ -130,7 +129,6 @@ class MainActivity : SimpleActivity() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@TargetApi(Build.VERSION_CODES.KITKAT)
|
|
||||||
private fun storeNewAlarmSound(uri: Uri) {
|
private fun storeNewAlarmSound(uri: Uri) {
|
||||||
var filename = getFilenameFromUri(uri)
|
var filename = getFilenameFromUri(uri)
|
||||||
if (filename.isEmpty()) {
|
if (filename.isEmpty()) {
|
||||||
|
@ -143,8 +141,10 @@ class MainActivity : SimpleActivity() {
|
||||||
yourAlarmSounds.add(AlarmSound(newAlarmSoundId, filename, uri.toString()))
|
yourAlarmSounds.add(AlarmSound(newAlarmSoundId, filename, uri.toString()))
|
||||||
config.yourAlarmSounds = Gson().toJson(yourAlarmSounds)
|
config.yourAlarmSounds = Gson().toJson(yourAlarmSounds)
|
||||||
|
|
||||||
val takeFlags = Intent.FLAG_GRANT_READ_URI_PERMISSION
|
if (isKitkatPlus()) {
|
||||||
contentResolver.takePersistableUriPermission(uri, takeFlags)
|
val takeFlags = Intent.FLAG_GRANT_READ_URI_PERMISSION
|
||||||
|
contentResolver.takePersistableUriPermission(uri, takeFlags)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun initFragments() {
|
private fun initFragments() {
|
||||||
|
|
|
@ -17,6 +17,7 @@ import com.simplemobiletools.clock.models.AlarmSound
|
||||||
import com.simplemobiletools.commons.extensions.getAdjustedPrimaryColor
|
import com.simplemobiletools.commons.extensions.getAdjustedPrimaryColor
|
||||||
import com.simplemobiletools.commons.extensions.setupDialogStuff
|
import com.simplemobiletools.commons.extensions.setupDialogStuff
|
||||||
import com.simplemobiletools.commons.extensions.showErrorToast
|
import com.simplemobiletools.commons.extensions.showErrorToast
|
||||||
|
import com.simplemobiletools.commons.helpers.isKitkatPlus
|
||||||
import com.simplemobiletools.commons.views.MyCompatRadioButton
|
import com.simplemobiletools.commons.views.MyCompatRadioButton
|
||||||
import kotlinx.android.synthetic.main.dialog_select_alarm_sound.view.*
|
import kotlinx.android.synthetic.main.dialog_select_alarm_sound.view.*
|
||||||
import java.util.LinkedHashSet
|
import java.util.LinkedHashSet
|
||||||
|
@ -83,10 +84,14 @@ class SelectAlarmSoundDialog(val activity: SimpleActivity, val currentUri: Strin
|
||||||
|
|
||||||
private fun alarmClicked(alarmSound: AlarmSound) {
|
private fun alarmClicked(alarmSound: AlarmSound) {
|
||||||
if (alarmSound.id == ADD_NEW_SOUND_ID) {
|
if (alarmSound.id == ADD_NEW_SOUND_ID) {
|
||||||
Intent(Intent.ACTION_OPEN_DOCUMENT).apply {
|
val action = if (isKitkatPlus()) Intent.ACTION_OPEN_DOCUMENT else Intent.ACTION_GET_CONTENT
|
||||||
|
Intent(action).apply {
|
||||||
type = "audio/*"
|
type = "audio/*"
|
||||||
activity.startActivityForResult(this, PICK_AUDIO_FILE_INTENT_ID)
|
activity.startActivityForResult(this, PICK_AUDIO_FILE_INTENT_ID)
|
||||||
flags = flags or Intent.FLAG_GRANT_PERSISTABLE_URI_PERMISSION
|
|
||||||
|
if (isKitkatPlus()) {
|
||||||
|
flags = flags or Intent.FLAG_GRANT_PERSISTABLE_URI_PERMISSION
|
||||||
|
}
|
||||||
}
|
}
|
||||||
dialog.dismiss()
|
dialog.dismiss()
|
||||||
} else {
|
} else {
|
||||||
|
|
Loading…
Reference in New Issue