Skip to content

Commit

Permalink
fixed bug: app would crash when trying to use an app shortuct without…
Browse files Browse the repository at this point in the history
… the correct permissions
  • Loading branch information
sds100 committed Apr 10, 2019
1 parent facb5d9 commit 8d3b3a8
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 5 deletions.
1 change: 1 addition & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
<uses-permission android:name="android.permission.INTERNET" />
<uses-permission android:name="android.permission.CAMERA" />
<uses-permission android:name="android.permission.VIBRATE" />

<uses-permission
android:name="android.permission.WRITE_SETTINGS"
tools:ignore="ProtectedPermissions" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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


/**
Expand Down Expand Up @@ -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) {
Expand All @@ -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)
}
}

Expand All @@ -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)
}
}

Expand Down
1 change: 1 addition & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,7 @@
<string name="error_need_to_enable_device_admin">Key Mapper needs to be a device administrator to use this action!</string>
<string name="error_camera_in_use">Camera is in use!</string>
<string name="error_in_do_not_disturb_mode">In Do Not Disturb mode!</string>
<string name="error_keymapper_doesnt_have_permission_app_shortcut">Key Mapper doesn\'t have permission to use that shortcut.</string>

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

0 comments on commit 8d3b3a8

Please sign in to comment.