check if we can generate a public uri from the selected reminder sound uri

This commit is contained in:
tibbi 2018-01-31 21:17:45 +01:00
parent f7010a9529
commit ba70e6b523
2 changed files with 17 additions and 4 deletions

View File

@ -7,6 +7,7 @@ import android.net.Uri
import android.os.Bundle import android.os.Bundle
import android.os.Parcelable import android.os.Parcelable
import android.text.TextUtils import android.text.TextUtils
import com.simplemobiletools.calendar.BuildConfig
import com.simplemobiletools.calendar.R import com.simplemobiletools.calendar.R
import com.simplemobiletools.calendar.dialogs.CustomEventReminderDialog import com.simplemobiletools.calendar.dialogs.CustomEventReminderDialog
import com.simplemobiletools.calendar.dialogs.SelectCalendarsDialog import com.simplemobiletools.calendar.dialogs.SelectCalendarsDialog
@ -23,6 +24,7 @@ import com.simplemobiletools.commons.helpers.PERMISSION_READ_CALENDAR
import com.simplemobiletools.commons.helpers.PERMISSION_WRITE_CALENDAR import com.simplemobiletools.commons.helpers.PERMISSION_WRITE_CALENDAR
import com.simplemobiletools.commons.models.RadioItem import com.simplemobiletools.commons.models.RadioItem
import kotlinx.android.synthetic.main.activity_settings.* import kotlinx.android.synthetic.main.activity_settings.*
import java.io.File
import java.util.* import java.util.*
class SettingsActivity : SimpleActivity() { class SettingsActivity : SimpleActivity() {
@ -367,12 +369,20 @@ class SettingsActivity : SimpleActivity() {
override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) { override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
if (resultCode == RESULT_OK) { if (resultCode == RESULT_OK) {
if (requestCode == GET_RINGTONE_URI) { if (requestCode == GET_RINGTONE_URI) {
val uri = data?.getParcelableExtra<Parcelable>(RingtoneManager.EXTRA_RINGTONE_PICKED_URI) var uri = data?.getParcelableExtra<Parcelable>(RingtoneManager.EXTRA_RINGTONE_PICKED_URI)
if (uri == null) { if (uri == null) {
config.reminderSound = "" config.reminderSound = ""
} else { } else {
settings_reminder_sound.text = RingtoneManager.getRingtone(this, uri as Uri)?.getTitle(this) try {
if ((uri as Uri).scheme == "file") {
uri = getFilePublicUri(File(uri.path), BuildConfig.APPLICATION_ID)
}
settings_reminder_sound.text = RingtoneManager.getRingtone(this, uri)?.getTitle(this)
config.reminderSound = uri.toString() config.reminderSound = uri.toString()
} catch (e: Exception) {
showErrorToast(e)
}
} }
} }
} }

View File

@ -199,7 +199,10 @@ private fun getNotification(context: Context, pendingIntent: PendingIntent, even
var soundUri = Uri.parse(context.config.reminderSound) var soundUri = Uri.parse(context.config.reminderSound)
if (soundUri.scheme == "file") { if (soundUri.scheme == "file") {
try {
soundUri = context.getFilePublicUri(File(soundUri.path), BuildConfig.APPLICATION_ID) soundUri = context.getFilePublicUri(File(soundUri.path), BuildConfig.APPLICATION_ID)
} catch (ignored: Exception) {
}
} }
val builder = NotificationCompat.Builder(context) val builder = NotificationCompat.Builder(context)