-
Notifications
You must be signed in to change notification settings - Fork 624
Notification trigger API #4183
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Notification trigger API #4183
Changes from all commits
ae8db00
50f4148
d633ffb
bfa8ca1
dd1967f
97322d5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,9 +14,11 @@ | |
|
||
package com.google.firebase.appdistribution; | ||
|
||
import android.app.Activity; | ||
import android.net.Uri; | ||
import androidx.annotation.NonNull; | ||
import androidx.annotation.Nullable; | ||
import androidx.annotation.StringRes; | ||
import com.google.android.gms.tasks.Task; | ||
import com.google.firebase.FirebaseApp; | ||
import com.google.firebase.appdistribution.internal.FirebaseAppDistributionProxy; | ||
|
@@ -34,6 +36,7 @@ | |
* <p>Call {@link #getInstance()} to get the singleton instance of {@link FirebaseAppDistribution}. | ||
*/ | ||
public interface FirebaseAppDistribution { | ||
|
||
/** | ||
* Updates the app to the newest release, if one is available. | ||
* | ||
|
@@ -125,7 +128,7 @@ public interface FirebaseAppDistribution { | |
* @param infoTextResourceId string resource ID of text to display to the tester before collecting | ||
* feedback data (e.g. Terms and Conditions) | ||
*/ | ||
void startFeedback(int infoTextResourceId); | ||
void startFeedback(@StringRes int infoTextResourceId); | ||
|
||
/** | ||
* Takes a screenshot, and starts an activity to collect and submit feedback from the tester. | ||
|
@@ -159,7 +162,7 @@ public interface FirebaseAppDistribution { | |
* @param screenshot URI to a bitmap containing a screenshot that will be included with the | ||
* report, or null to not include a screenshot | ||
*/ | ||
void startFeedback(@NonNull int infoTextResourceId, @Nullable Uri screenshot); | ||
void startFeedback(@StringRes int infoTextResourceId, @Nullable Uri screenshot); | ||
|
||
/** | ||
* Starts an activity to collect and submit feedback from the tester, along with the given | ||
|
@@ -179,6 +182,70 @@ public interface FirebaseAppDistribution { | |
*/ | ||
void startFeedback(@NonNull CharSequence infoText, @Nullable Uri screenshot); | ||
|
||
/** | ||
* Displays a notification that, when tapped, will take a screenshot of the current activity, then | ||
* start a new activity to collect and submit feedback from the tester along with the screenshot. | ||
* | ||
* <p>On Android 13 and above, this method requires the <a | ||
* href="https://developer.android.com/develop/ui/views/notifications/notification-permission">runtime | ||
* permission for sending notifications</a>: {@code POST_NOTIFICATIONS}. If your app targets | ||
* Android 13 (API level 33) or above, you should <a | ||
* href="https://developer.android.com/training/permissions/requesting">request the | ||
* permission</a>. | ||
* | ||
* <p>When the notification is tapped: | ||
* | ||
* <ol> | ||
* <li>If the app is open, take a screenshot of the current activity | ||
* <li>If tester is not signed in, presents the tester with a Google Sign-in UI | ||
* <li>Starts a full screen activity for the tester to compose and submit the feedback | ||
* </ol> | ||
* | ||
* @param infoTextResourceId string resource ID of text to display to the tester before collecting | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Does the underlying api require a resource id? if not, do we want to restrict to only allow resource ids as opposed to allowing passing in custom strings like constants? If resourceId is preferred, please make sure to annotate this param with There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We alternatively allow them to pass in a CharSequence, below. Supporting resource id is mostly for convenience, so they don't have to call There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. My preference is in the other direction. If we eliminate one, I'd vote for the overload with There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That's a good point, Kai. I actually just noticed that if you use So I'm tempted to remove the CharSequence option, but that would prevent the dev from using format strings: https://developer.android.com/guide/topics/resources/string-resource#formatting-strings I feel like we should support that. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would it make sense to add an overload that would mirror void showFeedbackNotification(
@NonNull InterruptionLevel interruptionLevel, @StringRes int infoTextResourceId, Object... formatArgs); There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We could, but if they want to use a format string AND html elements like This might seem like an edge case, but because this text will likely include links to terms and conditions I expect anyone who wants to use a format string will have to do this. |
||
* feedback data (e.g. Terms and Conditions) | ||
* @param interruptionLevel the level of interruption for the feedback notification. On platforms | ||
* below Android 8, this corresponds to a notification channel importance and once set cannot | ||
* be changed except by the user. | ||
*/ | ||
void showFeedbackNotification( | ||
@StringRes int infoTextResourceId, @NonNull InterruptionLevel interruptionLevel); | ||
|
||
/** | ||
* Displays a notification that, when tapped, will take a screenshot of the current activity, then | ||
* start a new activity to collect and submit feedback from the tester along with the screenshot. | ||
* | ||
* <p>On Android 13 and above, this method requires the <a | ||
* href="https://developer.android.com/develop/ui/views/notifications/notification-permission">runtime | ||
* permission for sending notifications</a>: {@code POST_NOTIFICATIONS}. If your app targets | ||
* Android 13 (API level 33) or above, you should <a | ||
* href="https://developer.android.com/training/permissions/requesting">request the | ||
* permission</a>. | ||
* | ||
* <p>When the notification is tapped: | ||
* | ||
* <ol> | ||
* <li>If the app is open, take a screenshot of the current activity | ||
* <li>If tester is not signed in, presents the tester with a Google Sign-in UI | ||
* <li>Starts a full screen activity for the tester to compose and submit the feedback | ||
* </ol> | ||
* | ||
* @param infoText text to display to the tester before collecting feedback data (e.g. Terms and | ||
* Conditions) | ||
* @param interruptionLevel the level of interruption for the feedback notification. On platforms | ||
* below Android 8, this corresponds to a notification channel importance and once set cannot | ||
* be changed except by the user. | ||
*/ | ||
void showFeedbackNotification( | ||
@NonNull CharSequence infoText, @NonNull InterruptionLevel interruptionLevel); | ||
|
||
/** | ||
* Hides the notification shown with {@link #showFeedbackNotification}. | ||
* | ||
* <p>This should be called in the {@link Activity#onDestroy} of the activity that showed the | ||
* notification. | ||
*/ | ||
void cancelFeedbackNotification(); | ||
|
||
/** Gets the singleton {@link FirebaseAppDistribution} instance. */ | ||
@NonNull | ||
static FirebaseAppDistribution getInstance() { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
// Copyright 2022 Google LLC | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package com.google.firebase.appdistribution; | ||
|
||
import android.app.NotificationManager; | ||
import androidx.core.app.NotificationCompat; | ||
|
||
/** An enum specifying the level of interruption of a notification when it is created. */ | ||
public enum InterruptionLevel { | ||
|
||
/** | ||
* Minimum interruption level. | ||
* | ||
* <p>Translates to {@link NotificationManager#IMPORTANCE_MIN} on Android O+ and {@link | ||
* NotificationCompat#PRIORITY_MIN} on older platforms. | ||
*/ | ||
MIN(NotificationManager.IMPORTANCE_MIN, NotificationCompat.PRIORITY_MIN), | ||
|
||
/** | ||
* Low interruption level. | ||
* | ||
* <p>Translates to {@link NotificationManager#IMPORTANCE_LOW} on Android O+ and {@link | ||
* NotificationCompat#PRIORITY_LOW} on older platforms. | ||
*/ | ||
LOW(NotificationManager.IMPORTANCE_LOW, NotificationCompat.PRIORITY_LOW), | ||
|
||
/** | ||
* Default interruption level. | ||
* | ||
* <p>Translates to {@link NotificationManager#IMPORTANCE_DEFAULT} on Android O+ and {@link | ||
* NotificationCompat#PRIORITY_DEFAULT} on older platforms. | ||
*/ | ||
DEFAULT(NotificationManager.IMPORTANCE_DEFAULT, NotificationCompat.PRIORITY_DEFAULT), | ||
|
||
/** | ||
* High interruption level. | ||
* | ||
* <p>Translates to {@link NotificationManager#IMPORTANCE_HIGH} on Android O+ and {@link | ||
* NotificationCompat#PRIORITY_HIGH} on older platforms. | ||
*/ | ||
HIGH(NotificationManager.IMPORTANCE_HIGH, NotificationCompat.PRIORITY_HIGH), | ||
|
||
/** | ||
* Maximum interruption level. | ||
* | ||
* <p>Translates to {@link NotificationManager#IMPORTANCE_HIGH} on Android O+ and {@link | ||
* NotificationCompat#PRIORITY_MAX} on older platforms. | ||
*/ | ||
MAX(NotificationManager.IMPORTANCE_HIGH, NotificationCompat.PRIORITY_MAX); | ||
|
||
/** | ||
* The notification channel importance corresponding to this interruption level on Android O+. | ||
* | ||
* @hide | ||
*/ | ||
public final int channelImportance; | ||
|
||
/** | ||
* The notification priority corresponding to this interruption level on older platforms. | ||
* | ||
* @hide | ||
*/ | ||
public final int notificationPriority; | ||
|
||
InterruptionLevel(int channelImportance, int notificationPriority) { | ||
this.channelImportance = channelImportance; | ||
this.notificationPriority = notificationPriority; | ||
} | ||
} |
Uh oh!
There was an error while loading. Please reload this page.