@@ -2,6 +2,7 @@ package com.google.firebase.example.messaging.kotlin
2
2
3
3
import android.Manifest
4
4
import android.content.pm.PackageManager
5
+ import android.os.Build
5
6
import android.os.Bundle
6
7
import android.util.Log
7
8
import android.widget.Toast
@@ -109,22 +110,22 @@ class MainActivity : AppCompatActivity() {
109
110
}
110
111
}
111
112
112
- // [START_EXCLUDE]
113
- @RequiresApi(33 )
114
- // [END_EXCLUDE]
115
113
private fun askNotificationPermission () {
116
- if (ContextCompat .checkSelfPermission(this , Manifest .permission.POST_NOTIFICATIONS ) ==
117
- PackageManager .PERMISSION_GRANTED
118
- ) {
119
- // FCM SDK (and your app) can post notifications.
120
- } else if (shouldShowRequestPermissionRationale(Manifest .permission.POST_NOTIFICATIONS )) {
121
- // TODO: display an educational UI explaining to the user the features that will be enabled
122
- // by them granting the POST_NOTIFICATION permission. This UI should provide the user
123
- // "OK" and "No thanks" buttons. If the user selects "OK," directly request the permission.
124
- // If the user selects "No thanks," allow the user to continue without notifications.
125
- } else {
126
- // Directly ask for the permission
127
- requestPermissionLauncher.launch(Manifest .permission.POST_NOTIFICATIONS )
114
+ // This is only necessary for API level >= 33 (TIRAMISU)
115
+ if (Build .VERSION .SDK_INT >= Build .VERSION_CODES .TIRAMISU ) {
116
+ if (ContextCompat .checkSelfPermission(this , Manifest .permission.POST_NOTIFICATIONS ) ==
117
+ PackageManager .PERMISSION_GRANTED
118
+ ) {
119
+ // FCM SDK (and your app) can post notifications.
120
+ } else if (shouldShowRequestPermissionRationale(Manifest .permission.POST_NOTIFICATIONS )) {
121
+ // TODO: display an educational UI explaining to the user the features that will be enabled
122
+ // by them granting the POST_NOTIFICATION permission. This UI should provide the user
123
+ // "OK" and "No thanks" buttons. If the user selects "OK," directly request the permission.
124
+ // If the user selects "No thanks," allow the user to continue without notifications.
125
+ } else {
126
+ // Directly ask for the permission
127
+ requestPermissionLauncher.launch(Manifest .permission.POST_NOTIFICATIONS )
128
+ }
128
129
}
129
130
}
130
131
// [END ask_post_notifications]
0 commit comments