From 8d3b3a8df34b523cda84debce079b0c71a86628a Mon Sep 17 00:00:00 2001 From: sds100 Date: Wed, 10 Apr 2019 15:00:28 +0100 Subject: [PATCH] fixed bug: app would crash when trying to use an app shortuct without the correct permissions --- app/src/main/AndroidManifest.xml | 1 + .../keymapper/delegate/ActionPerformerDelegate.kt | 12 +++++++----- app/src/main/res/values/strings.xml | 1 + 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 2d7816a722..ed9f814cdc 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -13,6 +13,7 @@ + diff --git a/app/src/main/java/io/github/sds100/keymapper/delegate/ActionPerformerDelegate.kt b/app/src/main/java/io/github/sds100/keymapper/delegate/ActionPerformerDelegate.kt index ba47e560e7..0caa5e2c07 100644 --- a/app/src/main/java/io/github/sds100/keymapper/delegate/ActionPerformerDelegate.kt +++ b/app/src/main/java/io/github/sds100/keymapper/delegate/ActionPerformerDelegate.kt @@ -14,7 +14,6 @@ import android.os.Vibrator import android.provider.MediaStore import android.provider.Settings import android.view.KeyEvent -import android.widget.Toast import androidx.lifecycle.Lifecycle import io.github.sds100.keymapper.* import io.github.sds100.keymapper.interfaces.IContext @@ -24,6 +23,7 @@ import io.github.sds100.keymapper.util.* import io.github.sds100.keymapper.util.FlagUtils.FLAG_SHOW_VOLUME_UI import io.github.sds100.keymapper.util.FlagUtils.FLAG_VIBRATE import org.jetbrains.anko.defaultSharedPreferences +import org.jetbrains.anko.toast /** @@ -51,7 +51,7 @@ class ActionPerformerDelegate( val key = str(R.string.key_pref_show_toast_when_action_performed) if (defaultSharedPreferences.getBoolean(key, bool(R.bool.default_value_show_toast))) { - Toast.makeText(this, R.string.performing_action, Toast.LENGTH_SHORT).show() + toast(R.string.performing_action) } when (action.type) { @@ -62,7 +62,7 @@ class ActionPerformerDelegate( if (intent != null) { startActivity(intent) } else { - Toast.makeText(this, R.string.error_app_isnt_installed, Toast.LENGTH_SHORT).show() + toast(R.string.error_app_isnt_installed) } } @@ -72,8 +72,10 @@ class ActionPerformerDelegate( try { startActivity(intent) - } catch (exception: ActivityNotFoundException) { - Toast.makeText(this, R.string.error_shortcut_not_found, Toast.LENGTH_SHORT).show() + } catch (e: ActivityNotFoundException) { + toast(R.string.error_shortcut_not_found) + } catch (e: SecurityException) { + toast(R.string.error_keymapper_doesnt_have_permission_app_shortcut) } } diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 67de1a9bb9..408d08a86f 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -266,6 +266,7 @@ Key Mapper needs to be a device administrator to use this action! Camera is in use! In Do Not Disturb mode! + Key Mapper doesn\'t have permission to use that shortcut. The accessibility service must be enabled for this app to work! Accessibility service is enabled!