Skip to content

Commit

Permalink
implement permission check for notifications on Android 13
Browse files Browse the repository at this point in the history
Signed-off-by: Andy Scherzinger <info@andy-scherzinger.de>
  • Loading branch information
AndyScherzinger committed Jul 26, 2023
1 parent 72e21c4 commit 560c9e1
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
*/
package com.nextcloud.talk.conversationlist

import android.Manifest
import android.animation.AnimatorInflater
import android.annotation.SuppressLint
import android.app.SearchManager
Expand Down Expand Up @@ -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()

Expand Down Expand Up @@ -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
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,4 +27,5 @@ interface PlatformPermissionUtil {
fun isMicrophonePermissionGranted(): Boolean
fun isBluetoothPermissionGranted(): Boolean
fun isFilesPermissionGranted(): Boolean
fun isPostNotificationsPermissionGranted(): Boolean
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down

0 comments on commit 560c9e1

Please sign in to comment.