14
14
15
15
package com .google .firebase .appdistribution ;
16
16
17
+ import android .app .Activity ;
17
18
import android .app .NotificationChannel ;
18
19
import android .net .Uri ;
20
+ import android .os .Build ;
21
+ import androidx .activity .result .ActivityResultCaller ;
19
22
import androidx .annotation .NonNull ;
20
23
import androidx .annotation .Nullable ;
24
+ import androidx .annotation .RequiresApi ;
21
25
import androidx .core .app .NotificationCompat ;
22
26
import com .google .android .gms .tasks .Task ;
23
27
import com .google .firebase .FirebaseApp ;
@@ -181,10 +185,43 @@ public interface FirebaseAppDistribution {
181
185
*/
182
186
void startFeedback (@ NonNull CharSequence infoText , @ Nullable Uri screenshot );
183
187
188
+ /**
189
+ * Requests the {@code POST_NOTIFICATIONS} permission, if it is not already granted.
190
+ *
191
+ * <p>This <b>must</b> be called from {@link Activity#onCreate}.
192
+ *
193
+ * <p>Android 13 (API level 33) and above support a <a
194
+ * href="https://developer.android.com/develop/ui/views/notifications/notification-permission">runtime
195
+ * permission for sending notifications</a>: {@code POST_NOTIFICATIONS}. If you target Android 13
196
+ * or higher and do not want to <a
197
+ * href="https://developer.android.com/training/permissions/requesting">request the permission</a>
198
+ * on your own, call this method to request the permission.
199
+ *
200
+ * <p>Only use this method if <b>all</b> of the following are true:
201
+ *
202
+ * <ol>
203
+ * <li>The device is running Android 13 or above
204
+ * <li>You want to use {@link #showFeedbackNotification} to collect feedback from your testers
205
+ * <li>You do not already dynamically request the {@code POST_NOTIFICATIONS} permission
206
+ * </ol>
207
+ *
208
+ * @param activity the activity being initialized (this method <b>must</b> be called from this
209
+ * activity's {@link Activity#onCreate})
210
+ */
211
+ @ RequiresApi (Build .VERSION_CODES .TIRAMISU )
212
+ <T extends Activity & ActivityResultCaller > void requestNotificationPermissions (
213
+ @ NonNull T activity );
214
+
184
215
/**
185
216
* Displays a notification that, when tapped, will take a screenshot of the current activity, then
186
217
* start a new activity to collect and submit feedback from the tester along with the screenshot.
187
218
*
219
+ * <p>On Android 13 and above, his method requires the <a
220
+ * href="https://developer.android.com/develop/ui/views/notifications/notification-permission">runtime
221
+ * permission for sending notifications</a>: {@code POST_NOTIFICATIONS}. Either <a
222
+ * href="https://developer.android.com/training/permissions/requesting">request the permission</a>
223
+ * on your own or call {@link #requestNotificationPermissions}.
224
+ *
188
225
* <p>When the notification is tapped:
189
226
*
190
227
* <ol>
@@ -193,16 +230,39 @@ public interface FirebaseAppDistribution {
193
230
* <li>Starts a full screen activity for the tester to compose and submit the feedback
194
231
* </ol>
195
232
*
196
- * <p>On platforms O and above, the notification will be created in its own notification channel.
233
+ * <p>On Android 8 and above, the notification will be created in its own notification channel.
197
234
*
198
235
* @param infoTextResourceId string resource ID of text to display to the tester before collecting
199
236
* feedback data (e.g. Terms and Conditions)
200
237
* @param importance the amount the user should be interrupted by notifications from the feedback
238
+ * notification channel. See {@link NotificationChannel#setImportance}. On platforms below
239
+ * Android 8, the importance will be translated into a comparable notification priority (see
240
+ * {@link NotificationCompat.Builder#setPriority}).
241
+ */
242
+ void showFeedbackNotification (@ NonNull int infoTextResourceId , int importance );
243
+
244
+ /**
245
+ * Displays a notification that, when tapped, will take a screenshot of the current activity, then
246
+ * start a new activity to collect and submit feedback from the tester along with the screenshot.
247
+ *
248
+ * <p>When the notification is tapped:
249
+ *
250
+ * <ol>
251
+ * <li>If the app is open, take a screenshot of the current activity
252
+ * <li>If tester is not signed in, presents the tester with a Google Sign-in UI
253
+ * <li>Starts a full screen activity for the tester to compose and submit the feedback
254
+ * </ol>
255
+ *
256
+ * <p>On Android 8 and above, the notification will be created in its own notification channel.
257
+ *
258
+ * @param infoText text to display to the tester before collecting feedback data (e.g. Terms and
259
+ * Conditions)
260
+ * @param importance the amount the user should be interrupted by notifications from the feedback
201
261
* notification channel. See {@link NotificationChannel#setImportance}. On platforms below O,
202
262
* the importance will be translated into a comparable notification priority (see {@link
203
263
* NotificationCompat.Builder#setPriority}).
204
264
*/
205
- void showFeedbackNotification (@ NonNull int infoTextResourceId , int importance );
265
+ void showFeedbackNotification (@ NonNull CharSequence infoText , int importance );
206
266
207
267
/** Gets the singleton {@link FirebaseAppDistribution} instance. */
208
268
@ NonNull
0 commit comments