@@ -10,6 +10,7 @@ import android.media.AudioDeviceInfo
1010import android.media.AudioManager
1111import android.os.Build
1212import androidx.annotation.RequiresApi
13+ import androidx.core.app.ActivityCompat
1314import androidx.core.app.NotificationCompat
1415import androidx.core.content.ContextCompat
1516import com.facebook.react.bridge.Arguments
@@ -134,16 +135,30 @@ object MediaSessionManager {
134135 permissionAwareActivity.requestPermissions(arrayOf(Manifest .permission.RECORD_AUDIO ), RECORDING_REQUEST_CODE , permissionListener)
135136 }
136137
137- fun checkRecordingPermissions (): String =
138- if (reactContext.get()!! .checkSelfPermission(
138+ fun checkRecordingPermissions (): String {
139+ val context = reactContext.get()!!
140+
141+ if (context.checkSelfPermission(Manifest .permission.RECORD_AUDIO ) == PackageManager .PERMISSION_GRANTED ) {
142+ return " Granted"
143+ }
144+
145+ // Permission not granted - check if we should show rationale
146+ val activity = context.currentActivity
147+ if (activity != null &&
148+ ActivityCompat .shouldShowRequestPermissionRationale(
149+ activity,
139150 Manifest .permission.RECORD_AUDIO ,
140- ) == PackageManager . PERMISSION_GRANTED
151+ )
141152 ) {
142- " Granted"
143- } else {
144- " Denied"
153+ // User previously denied but didn't select "Don't ask again"
154+ return " Denied"
145155 }
146156
157+ // Either never asked OR user selected "Don't ask again"
158+ // Return "Undetermined" to match iOS behavior and let caller decide to request
159+ return " Undetermined"
160+ }
161+
147162 fun requestNotificationPermissions (permissionListener : PermissionListener ) {
148163 if (Build .VERSION .SDK_INT >= Build .VERSION_CODES .TIRAMISU ) {
149164 val permissionAwareActivity = reactContext.get()!! .currentActivity as PermissionAwareActivity
@@ -166,14 +181,26 @@ object MediaSessionManager {
166181
167182 fun checkNotificationPermissions (): String {
168183 if (Build .VERSION .SDK_INT >= Build .VERSION_CODES .TIRAMISU ) {
169- return if (reactContext.get()!! .checkSelfPermission(
184+ val context = reactContext.get()!!
185+
186+ if (context.checkSelfPermission(Manifest .permission.POST_NOTIFICATIONS ) == PackageManager .PERMISSION_GRANTED ) {
187+ return " Granted"
188+ }
189+
190+ // Permission not granted - check if we should show rationale
191+ val activity = context.currentActivity
192+ if (activity != null &&
193+ ActivityCompat .shouldShowRequestPermissionRationale(
194+ activity,
170195 Manifest .permission.POST_NOTIFICATIONS ,
171- ) == PackageManager . PERMISSION_GRANTED
196+ )
172197 ) {
173- " Granted"
174- } else {
175- " Denied"
198+ // User previously denied but didn't select "Don't ask again"
199+ return " Denied"
176200 }
201+
202+ // Either never asked OR user selected "Don't ask again"
203+ return " Undetermined"
177204 }
178205 // For Android < 13, permission is granted by default
179206 return " Granted"
0 commit comments