implement permission check for notifications on Android 13

Signed-off-by: Andy Scherzinger <info@andy-scherzinger.de>
This commit is contained in:
Andy Scherzinger 2023-07-26 21:01:00 +02:00
parent 46322b2b63
commit 2df415b36e
No known key found for this signature in database
GPG key ID: 6CADC7E3523C308B
3 changed files with 23 additions and 0 deletions

View file

@ -27,6 +27,7 @@
*/
package com.nextcloud.talk.conversationlist
import android.Manifest
import android.animation.AnimatorInflater
import android.annotation.SuppressLint
import android.app.SearchManager
@ -217,6 +218,19 @@ class ConversationsListActivity :
onBackPressedDispatcher.addCallback(this, onBackPressedCallback)
}
override fun onPostCreate(savedInstanceState: Bundle?) {
super.onPostCreate(savedInstanceState);
// handle notification permission on API level >= 33
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU
&& !platformPermissionUtil.isPostNotificationsPermissionGranted()) {
requestPermissions(
arrayOf(Manifest.permission.POST_NOTIFICATIONS),
REQUEST_POST_NOTIFICATIONS_PERMISSION
)
}
}
override fun onResume() {
super.onResume()
@ -1506,5 +1520,6 @@ class ConversationsListActivity :
const val CLIENT_UPGRADE_GPLAY_LINK = "https://play.google.com/store/apps/details?id="
const val HTTP_SERVICE_UNAVAILABLE = 503
const val MAINTENANCE_MODE_HEADER_KEY = "X-Nextcloud-Maintenance-Mode"
const val REQUEST_POST_NOTIFICATIONS_PERMISSION = 111
}
}

View file

@ -27,4 +27,5 @@ interface PlatformPermissionUtil {
fun isMicrophonePermissionGranted(): Boolean
fun isBluetoothPermissionGranted(): Boolean
fun isFilesPermissionGranted(): Boolean
fun isPostNotificationsPermissionGranted(): Boolean
}

View file

@ -102,6 +102,13 @@ class PlatformPermissionUtilImpl(private val context: Context) : PlatformPermiss
}
}
override fun isPostNotificationsPermissionGranted(): Boolean {
return PermissionChecker.checkSelfPermission(
context,
Manifest.permission.POST_NOTIFICATIONS
) == PermissionChecker.PERMISSION_GRANTED
}
companion object {
private val TAG = PlatformPermissionUtilImpl::class.simpleName
}