diff --git a/src/android/com/adobe/phonegap/push/PushPlugin.kt b/src/android/com/adobe/phonegap/push/PushPlugin.kt index 904c4262b..dc20a78a2 100644 --- a/src/android/com/adobe/phonegap/push/PushPlugin.kt +++ b/src/android/com/adobe/phonegap/push/PushPlugin.kt @@ -441,9 +441,9 @@ class PushPlugin : CordovaPlugin() { pushContext = callbackContext pluginInitData = data; - var hasPermission = checkForPostNotificationsPermission() - if (!hasPermission) + if (!checkForPostNotificationsPermission()) { return + } cordova.threadPool.execute(Runnable { Log.v(TAG, formatLogMessage("Data=$data")) @@ -612,8 +612,13 @@ class PushPlugin : CordovaPlugin() { private fun checkForPostNotificationsPermission(): Boolean { if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) { - if (!PermissionHelper.hasPermission(this, Manifest.permission.POST_NOTIFICATIONS)) - { + if (!PermissionHelper.hasPermission(this, Manifest.permission.POST_NOTIFICATIONS)) { + if (ActivityCompat.shouldShowRequestPermissionRationale( + activity, + Manifest.permission.POST_NOTIFICATIONS + )) { + return false + } PermissionHelper.requestPermission( this, REQ_CODE_INITIALIZE_PLUGIN, @@ -622,7 +627,6 @@ class PushPlugin : CordovaPlugin() { return false } } - return true }