Skip to content

Commit

Permalink
#814 feat: show system dialog to remove Key Mapper from background op…
Browse files Browse the repository at this point in the history
…timisation [2]
  • Loading branch information
sds100 committed Nov 4, 2021
1 parent a074dc4 commit c41c9a4
Showing 1 changed file with 15 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -207,17 +207,7 @@ class RequestPermissionDelegate(
messageResource = R.string.dialog_message_disable_battery_optimisation

positiveButton(R.string.pos_turn_off_stock_battery_optimisation) {

try {
val intent = Intent(
Settings.ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS,
Uri.parse("package:${Constants.PACKAGE_NAME}")
)

activity.startActivity(intent)
} catch (e: ActivityNotFoundException) {
activity.longToast(R.string.error_battery_optimisation_activity_not_found)
}
showBatteryOptimisationExemptionSystemDialog()
}

negativeButton(R.string.neg_cancel) { it.cancel() }
Expand All @@ -232,14 +222,21 @@ class RequestPermissionDelegate(
show()
}
} else {
try {
val intent =
Intent(Settings.ACTION_IGNORE_BATTERY_OPTIMIZATION_SETTINGS)
showBatteryOptimisationExemptionSystemDialog()
}
}

activity.startActivity(intent)
} catch (e: ActivityNotFoundException) {
longToast(R.string.error_battery_optimisation_activity_not_found)
}
@RequiresApi(Build.VERSION_CODES.M)
private fun showBatteryOptimisationExemptionSystemDialog() {
try {
val intent = Intent(
Settings.ACTION_REQUEST_IGNORE_BATTERY_OPTIMIZATIONS,
Uri.parse("package:${Constants.PACKAGE_NAME}")
)

activity.startActivity(intent)
} catch (e: ActivityNotFoundException) {
activity.longToast(R.string.error_battery_optimisation_activity_not_found)
}
}
}

0 comments on commit c41c9a4

Please sign in to comment.