diff --git a/app/src/main/kotlin/com/github/gotify/settings/SettingsActivity.kt b/app/src/main/kotlin/com/github/gotify/settings/SettingsActivity.kt index 9f4ef92..26c4516 100644 --- a/app/src/main/kotlin/com/github/gotify/settings/SettingsActivity.kt +++ b/app/src/main/kotlin/com/github/gotify/settings/SettingsActivity.kt @@ -5,8 +5,10 @@ import android.content.DialogInterface import android.content.Intent import android.content.SharedPreferences import android.content.SharedPreferences.OnSharedPreferenceChangeListener +import android.net.Uri import android.os.Build import android.os.Bundle +import android.provider.Settings import android.view.MenuItem import android.view.View import androidx.appcompat.app.AppCompatActivity @@ -97,6 +99,14 @@ internal class SettingsActivity : AppCompatActivity(), OnSharedPreferenceChangeL Utils.setExcludeFromRecent(requireContext(), value as Boolean) return@OnPreferenceChangeListener true } + findPreference( + getString(R.string.setting_key_intent_dialog_permission) + )?.let { + it.setOnPreferenceChangeListener { _, _ -> + openSystemAlertWindowPermissionPage() + } + } + checkSystemAlertWindowPermission() } override fun onDisplayPreferenceDialog(preference: Preference) { @@ -107,6 +117,35 @@ internal class SettingsActivity : AppCompatActivity(), OnSharedPreferenceChangeL } } + override fun onResume() { + super.onResume() + checkSystemAlertWindowPermission() + } + + private fun openSystemAlertWindowPermissionPage(): Boolean { + Intent( + Settings.ACTION_MANAGE_OVERLAY_PERMISSION, + Uri.parse("package:${requireContext().packageName}") + ).apply { + startActivity(this) + } + return true + } + + private fun checkSystemAlertWindowPermission() { + findPreference( + getString(R.string.setting_key_intent_dialog_permission) + )?.let { + val canDrawOverlays = Settings.canDrawOverlays(requireContext()) + it.isChecked = canDrawOverlays + it.summary = if (canDrawOverlays) { + getString(R.string.setting_summary_intent_dialog_permission_granted) + } else { + getString(R.string.setting_summary_intent_dialog_permission) + } + } + } + private fun showListPreferenceDialog(preference: ListPreference) { val dialogFragment = MaterialListPreference() dialogFragment.arguments = Bundle(1).apply { putString("key", preference.key) } diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 478b4d3..b79f30e 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -86,6 +86,10 @@ notification_channels exclude_from_recent Exclude from recents + Intent Action Permission + intent_dialog_permission + To always show incoming intent URLs, give permission to show this app on top of other apps. + Permission granted. Push message App: Priority: diff --git a/app/src/main/res/xml/root_preferences.xml b/app/src/main/res/xml/root_preferences.xml index 2373083..d6d4ad0 100644 --- a/app/src/main/res/xml/root_preferences.xml +++ b/app/src/main/res/xml/root_preferences.xml @@ -1,5 +1,6 @@ + xmlns:app="http://schemas.android.com/apk/res-auto" + xmlns:tools="http://schemas.android.com/tools"> + +