diff options
author | Torsten Grote <t@grobox.de> | 2020-09-08 13:43:04 -0300 |
---|---|---|
committer | Torsten Grote <t@grobox.de> | 2020-09-08 13:43:04 -0300 |
commit | 7260531f37b5832b3a0f8059bf931919a6e0b059 (patch) | |
tree | 84da13afb29ed40c61b05da6ba9d117fb706c32a /taler-kotlin-android | |
parent | c09cc9cf95244abe6b825495c2029201223be741 (diff) | |
download | taler-android-7260531f37b5832b3a0f8059bf931919a6e0b059.tar.gz taler-android-7260531f37b5832b3a0f8059bf931919a6e0b059.tar.bz2 taler-android-7260531f37b5832b3a0f8059bf931919a6e0b059.zip |
[wallet] change how we check if launching intents is safe
Resolving activities won't work anymore in Android 11.
See: https://cketti.de/2020/09/03/avoid-intent-resolveactivity/
Diffstat (limited to 'taler-kotlin-android')
-rw-r--r-- | taler-kotlin-android/src/main/java/net/taler/common/AndroidUtils.kt | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/taler-kotlin-android/src/main/java/net/taler/common/AndroidUtils.kt b/taler-kotlin-android/src/main/java/net/taler/common/AndroidUtils.kt index 72740df..c925515 100644 --- a/taler-kotlin-android/src/main/java/net/taler/common/AndroidUtils.kt +++ b/taler-kotlin-android/src/main/java/net/taler/common/AndroidUtils.kt @@ -16,6 +16,7 @@ package net.taler.common +import android.content.ActivityNotFoundException import android.content.Context import android.content.Context.CONNECTIVITY_SERVICE import android.content.Intent @@ -35,6 +36,7 @@ import android.text.format.DateUtils.FORMAT_SHOW_YEAR import android.text.format.DateUtils.MINUTE_IN_MILLIS import android.text.format.DateUtils.formatDateTime import android.text.format.DateUtils.getRelativeTimeSpanString +import android.util.Log import android.view.View import android.view.View.INVISIBLE import android.view.View.VISIBLE @@ -100,8 +102,12 @@ fun Context.showLogViewer() { startActivity(lynxActivityIntent) } -fun Intent.isSafe(context: Context): Boolean { - return context.packageManager.queryIntentActivities(this, MATCH_DEFAULT_ONLY).isNotEmpty() +fun Fragment.startActivitySafe(intent: Intent) { + try { + startActivity(intent) + } catch (e: ActivityNotFoundException) { + Log.e("taler-kotlin-android", "Error starting $intent", e) + } } fun Fragment.navigate(directions: NavDirections) = findNavController().navigate(directions) |