diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 23bc3da..85aedd8 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -2,6 +2,7 @@ + diff --git a/app/src/main/java/org/secuso/privacyfriendlypaindiary/activities/SettingsActivity.kt b/app/src/main/java/org/secuso/privacyfriendlypaindiary/activities/SettingsActivity.kt index 18a0fde..30b3b43 100644 --- a/app/src/main/java/org/secuso/privacyfriendlypaindiary/activities/SettingsActivity.kt +++ b/app/src/main/java/org/secuso/privacyfriendlypaindiary/activities/SettingsActivity.kt @@ -16,13 +16,18 @@ */ package org.secuso.privacyfriendlypaindiary.activities +import android.Manifest import android.app.AlertDialog import android.content.SharedPreferences import android.content.SharedPreferences.OnSharedPreferenceChangeListener +import android.content.pm.PackageManager +import android.os.Build import android.os.Bundle import android.preference.Preference.OnPreferenceClickListener import android.preference.PreferenceFragment import android.preference.PreferenceManager +import androidx.core.app.ActivityCompat +import androidx.core.content.ContextCompat import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.launch import kotlinx.coroutines.runBlocking @@ -56,6 +61,10 @@ class SettingsActivity : BaseActivity() { } class GeneralPreferenceFragment : PreferenceFragment(), OnSharedPreferenceChangeListener { + companion object { + const val REQUEST_CODE_POST_NOTIFICATION = 3 + } + override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) initPreferences() @@ -87,6 +96,7 @@ class SettingsActivity : BaseActivity() { } override fun onSharedPreferenceChanged(sharedPreferences: SharedPreferences, key: String?) { + checkPermission() if (key == KEY_PREF_REMINDER) { val enabled = sharedPreferences.getBoolean(KEY_PREF_REMINDER, false) if (enabled) { @@ -103,6 +113,25 @@ class SettingsActivity : BaseActivity() { } } + private fun checkPermission(): Boolean { + //Check for notification permission and exact alarm permission + if ((Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU + && ContextCompat.checkSelfPermission(this.context, Manifest.permission.POST_NOTIFICATIONS) != PackageManager.PERMISSION_GRANTED) + ) { + AlertDialog.Builder(this.context) + .setMessage(R.string.dialog_need_permission_for_notifications) + .setPositiveButton(android.R.string.ok) { _, _ -> + ActivityCompat.requestPermissions(this.activity, arrayOf(Manifest.permission.POST_NOTIFICATIONS), REQUEST_CODE_POST_NOTIFICATION) + } + .setTitle(R.string.dialog_need_permission_for_notifications_title) + .setCancelable(true) + .create() + .show() + return false + } + return true + } + private fun resetApp() { runBlocking { launch(Dispatchers.IO) { diff --git a/app/src/main/res/values-de/strings.xml b/app/src/main/res/values-de/strings.xml index 0d1e8b2..72920bc 100644 --- a/app/src/main/res/values-de/strings.xml +++ b/app/src/main/res/values-de/strings.xml @@ -164,6 +164,8 @@ PDF wurde im Dokumenten-Ordner gespeichert. Unbekannter Fehler: PDF konnte nicht gespeichert werden. Seien Sie vorsichtig, mit wem Sie Ihre medizinischen Informationen teilen. + Für diese Funktion ist die Berechtigung zum Senden von Benachrichtigungen erforderlich. + Benachrichtigungen aktivieren diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml index 219e90e..48fb00a 100644 --- a/app/src/main/res/values/strings.xml +++ b/app/src/main/res/values/strings.xml @@ -169,5 +169,7 @@ PDF was saved to documents folder. Unknown Error: PDF could not be saved. Be careful who you share your medical information with. + Permission to send notifications is needed for this feature. + Enable notifications \ No newline at end of file