|
14 | 14 |
|
15 | 15 | package com.google.firebase.appdistribution;
|
16 | 16 |
|
| 17 | +import android.app.Activity; |
| 18 | +import android.app.NotificationChannel; |
17 | 19 | import android.net.Uri;
|
| 20 | +import android.os.Build; |
| 21 | +import androidx.activity.result.ActivityResultCaller; |
18 | 22 | import androidx.annotation.NonNull;
|
19 | 23 | import androidx.annotation.Nullable;
|
| 24 | +import androidx.annotation.RequiresApi; |
| 25 | +import androidx.core.app.NotificationCompat; |
20 | 26 | import com.google.android.gms.tasks.Task;
|
21 | 27 | import com.google.firebase.FirebaseApp;
|
22 | 28 | import com.google.firebase.appdistribution.internal.FirebaseAppDistributionProxy;
|
@@ -179,6 +185,94 @@ public interface FirebaseAppDistribution {
|
179 | 185 | */
|
180 | 186 | void startFeedback(@NonNull CharSequence infoText, @Nullable Uri screenshot);
|
181 | 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. This is helpful if you use the {@link |
| 199 | + * #updateIfNewReleaseAvailable} method, which shows notifications. |
| 200 | + * |
| 201 | + * @param activity the activity being initialized (this method <b>must</b> be called from this |
| 202 | + * activity's {@link Activity#onCreate}) |
| 203 | + */ |
| 204 | + @RequiresApi(Build.VERSION_CODES.TIRAMISU) |
| 205 | + <T extends Activity & ActivityResultCaller> void requestNotificationPermissions( |
| 206 | + @NonNull T activity); |
| 207 | + |
| 208 | + /** |
| 209 | + * Displays a notification that, when tapped, will take a screenshot of the current activity, then |
| 210 | + * start a new activity to collect and submit feedback from the tester along with the screenshot. |
| 211 | + * |
| 212 | + * <p>On Android 13 and above, his method requires the <a |
| 213 | + * href="https://developer.android.com/develop/ui/views/notifications/notification-permission">runtime |
| 214 | + * permission for sending notifications</a>: {@code POST_NOTIFICATIONS}. Either <a |
| 215 | + * href="https://developer.android.com/training/permissions/requesting">request the permission</a> |
| 216 | + * on your own or call {@link #requestNotificationPermissions}. |
| 217 | + * |
| 218 | + * <p>When the notification is tapped: |
| 219 | + * |
| 220 | + * <ol> |
| 221 | + * <li>If the app is open, take a screenshot of the current activity |
| 222 | + * <li>If tester is not signed in, presents the tester with a Google Sign-in UI |
| 223 | + * <li>Starts a full screen activity for the tester to compose and submit the feedback |
| 224 | + * </ol> |
| 225 | + * |
| 226 | + * <p>On Android 8 and above, the notification will be created in its own notification channel. |
| 227 | + * |
| 228 | + * @param infoTextResourceId string resource ID of text to display to the tester before collecting |
| 229 | + * feedback data (e.g. Terms and Conditions) |
| 230 | + * @param importance the amount the user should be interrupted by notifications from the feedback |
| 231 | + * notification channel. Once the channel's importance is set it cannot be changed except by |
| 232 | + * the user. See {@link NotificationChannel#setImportance}. On platforms below Android 8, the |
| 233 | + * importance will be translated into a comparable notification priority (see {@link |
| 234 | + * NotificationCompat.Builder#setPriority}). |
| 235 | + */ |
| 236 | + void showFeedbackNotification(@NonNull int infoTextResourceId, int importance); |
| 237 | + |
| 238 | + /** |
| 239 | + * Displays a notification that, when tapped, will take a screenshot of the current activity, then |
| 240 | + * start a new activity to collect and submit feedback from the tester along with the screenshot. |
| 241 | + * |
| 242 | + * <p>On Android 13 and above, his method requires the <a |
| 243 | + * href="https://developer.android.com/develop/ui/views/notifications/notification-permission">runtime |
| 244 | + * permission for sending notifications</a>: {@code POST_NOTIFICATIONS}. Either <a |
| 245 | + * href="https://developer.android.com/training/permissions/requesting">request the permission</a> |
| 246 | + * on your own or call {@link #requestNotificationPermissions}. |
| 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 |
| 261 | + * notification channel. Once the channel's importance is set it cannot be changed except by |
| 262 | + * the user. See {@link NotificationChannel#setImportance}. On platforms below Android 8, the |
| 263 | + * importance will be translated into a comparable notification priority (see {@link |
| 264 | + * NotificationCompat.Builder#setPriority}). |
| 265 | + */ |
| 266 | + void showFeedbackNotification(@NonNull CharSequence infoText, int importance); |
| 267 | + |
| 268 | + /** |
| 269 | + * Hides the notification shown with {@link #showFeedbackNotification}. |
| 270 | + * |
| 271 | + * <p>This should be called in the {@link Activity#onDestroy} of the activity that showed the |
| 272 | + * notification. |
| 273 | + */ |
| 274 | + void hideFeedbackNotification(); |
| 275 | + |
182 | 276 | /** Gets the singleton {@link FirebaseAppDistribution} instance. */
|
183 | 277 | @NonNull
|
184 | 278 | static FirebaseAppDistribution getInstance() {
|
|
0 commit comments