Skip to content

Commit 8d3b3a8

Browse files
author
sds100
committed
fixed bug: app would crash when trying to use an app shortuct without the correct permissions
1 parent facb5d9 commit 8d3b3a8

File tree

3 files changed

+9
-5
lines changed

3 files changed

+9
-5
lines changed

app/src/main/AndroidManifest.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
<uses-permission android:name="android.permission.INTERNET" />
1414
<uses-permission android:name="android.permission.CAMERA" />
1515
<uses-permission android:name="android.permission.VIBRATE" />
16+
1617
<uses-permission
1718
android:name="android.permission.WRITE_SETTINGS"
1819
tools:ignore="ProtectedPermissions" />

app/src/main/java/io/github/sds100/keymapper/delegate/ActionPerformerDelegate.kt

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ import android.os.Vibrator
1414
import android.provider.MediaStore
1515
import android.provider.Settings
1616
import android.view.KeyEvent
17-
import android.widget.Toast
1817
import androidx.lifecycle.Lifecycle
1918
import io.github.sds100.keymapper.*
2019
import io.github.sds100.keymapper.interfaces.IContext
@@ -24,6 +23,7 @@ import io.github.sds100.keymapper.util.*
2423
import io.github.sds100.keymapper.util.FlagUtils.FLAG_SHOW_VOLUME_UI
2524
import io.github.sds100.keymapper.util.FlagUtils.FLAG_VIBRATE
2625
import org.jetbrains.anko.defaultSharedPreferences
26+
import org.jetbrains.anko.toast
2727

2828

2929
/**
@@ -51,7 +51,7 @@ class ActionPerformerDelegate(
5151
val key = str(R.string.key_pref_show_toast_when_action_performed)
5252

5353
if (defaultSharedPreferences.getBoolean(key, bool(R.bool.default_value_show_toast))) {
54-
Toast.makeText(this, R.string.performing_action, Toast.LENGTH_SHORT).show()
54+
toast(R.string.performing_action)
5555
}
5656

5757
when (action.type) {
@@ -62,7 +62,7 @@ class ActionPerformerDelegate(
6262
if (intent != null) {
6363
startActivity(intent)
6464
} else {
65-
Toast.makeText(this, R.string.error_app_isnt_installed, Toast.LENGTH_SHORT).show()
65+
toast(R.string.error_app_isnt_installed)
6666
}
6767
}
6868

@@ -72,8 +72,10 @@ class ActionPerformerDelegate(
7272

7373
try {
7474
startActivity(intent)
75-
} catch (exception: ActivityNotFoundException) {
76-
Toast.makeText(this, R.string.error_shortcut_not_found, Toast.LENGTH_SHORT).show()
75+
} catch (e: ActivityNotFoundException) {
76+
toast(R.string.error_shortcut_not_found)
77+
} catch (e: SecurityException) {
78+
toast(R.string.error_keymapper_doesnt_have_permission_app_shortcut)
7779
}
7880
}
7981

app/src/main/res/values/strings.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,6 +266,7 @@
266266
<string name="error_need_to_enable_device_admin">Key Mapper needs to be a device administrator to use this action!</string>
267267
<string name="error_camera_in_use">Camera is in use!</string>
268268
<string name="error_in_do_not_disturb_mode">In Do Not Disturb mode!</string>
269+
<string name="error_keymapper_doesnt_have_permission_app_shortcut">Key Mapper doesn\'t have permission to use that shortcut.</string>
269270

270271
<string name="error_accessibility_service_disabled">The accessibility service must be enabled for this app to work!</string>
271272
<string name="error_accessibility_service_enabled">Accessibility service is enabled!</string>

0 commit comments

Comments
 (0)