catch IllegalStateException
This commit is contained in:
parent
e89d263cdc
commit
65719b79d2
2 changed files with 15 additions and 4 deletions
|
@ -50,12 +50,20 @@ class AndroidPermission @Inject constructor(
|
||||||
}
|
}
|
||||||
if (test) {
|
if (test) {
|
||||||
if (activity is DaggerAppCompatActivityWithResult)
|
if (activity is DaggerAppCompatActivityWithResult)
|
||||||
activity.requestMultiplePermissions.launch(permissions)
|
try {
|
||||||
|
activity.requestMultiplePermissions.launch(permissions)
|
||||||
|
} catch (ignored: IllegalStateException) {
|
||||||
|
ToastUtils.errorToast(activity, rh.gs(R.string.error_asking_for_permissions))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (testBattery) {
|
if (testBattery) {
|
||||||
try {
|
try {
|
||||||
if (activity is DaggerAppCompatActivityWithResult)
|
if (activity is DaggerAppCompatActivityWithResult)
|
||||||
activity.callForBatteryOptimization.launch(null)
|
try {
|
||||||
|
activity.callForBatteryOptimization.launch(null)
|
||||||
|
} catch (ignored: IllegalStateException) {
|
||||||
|
ToastUtils.errorToast(activity, rh.gs(R.string.error_asking_for_permissions))
|
||||||
|
}
|
||||||
} catch (e: ActivityNotFoundException) {
|
} catch (e: ActivityNotFoundException) {
|
||||||
permissionBatteryOptimizationFailed = true
|
permissionBatteryOptimizationFailed = true
|
||||||
OKDialog.show(activity, rh.gs(R.string.permission), rh.gs(R.string.alert_dialog_permission_battery_optimization_failed)) { activity.recreate() }
|
OKDialog.show(activity, rh.gs(R.string.permission), rh.gs(R.string.alert_dialog_permission_battery_optimization_failed)) { activity.recreate() }
|
||||||
|
@ -145,8 +153,10 @@ class AndroidPermission @Inject constructor(
|
||||||
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.P) {
|
if (Build.VERSION.SDK_INT > Build.VERSION_CODES.P) {
|
||||||
// Show alert dialog to the user saying a separate permission is needed
|
// Show alert dialog to the user saying a separate permission is needed
|
||||||
// Launch the settings activity if the user prefers
|
// Launch the settings activity if the user prefers
|
||||||
val intent = Intent(Settings.ACTION_MANAGE_OVERLAY_PERMISSION,
|
val intent = Intent(
|
||||||
Uri.parse("package:" + activity.packageName))
|
Settings.ACTION_MANAGE_OVERLAY_PERMISSION,
|
||||||
|
Uri.parse("package:" + activity.packageName)
|
||||||
|
)
|
||||||
activity.startActivity(intent)
|
activity.startActivity(intent)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1250,6 +1250,7 @@
|
||||||
<string name="blocked_by_charging">Blocked by charging options</string>
|
<string name="blocked_by_charging">Blocked by charging options</string>
|
||||||
<string name="blocked_by_connectivity">Blocked by connectivity options</string>
|
<string name="blocked_by_connectivity">Blocked by connectivity options</string>
|
||||||
<string name="no_watch_connected">(No Watch Connected)</string>
|
<string name="no_watch_connected">(No Watch Connected)</string>
|
||||||
|
<string name="error_asking_for_permissions">Error asking for permissions</string>
|
||||||
|
|
||||||
|
|
||||||
</resources>
|
</resources>
|
||||||
|
|
Loading…
Reference in a new issue