Skip to content

Implement notification trigger #4159

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

Merged
merged 4 commits into from
Oct 3, 2022
Merged

Conversation

kaibolay
Copy link
Contributor

No description provided.

@google-oss-bot
Copy link
Contributor

google-oss-bot commented Sep 30, 2022

@google-oss-bot
Copy link
Contributor

google-oss-bot commented Sep 30, 2022

val channel = NotificationChannel(
FEEBACK_NOTIFICATION_CHANNEL_ID,
application.getString(R.string.feedback_notification_channel_name),
NotificationManager.IMPORTANCE_HIGH
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought we were going to use a low importance so that it didn't emit a sound or anything.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, but unfortunately low importance messages sometimes just don't show up at all 😬 So I decided to err on the side of visibility - making sure the notification is seen. Since this is sample code selecting the appropriate importance is ultimately up to the developers integrating code based on this example into their app.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Got it. I think it could be worth trying to make sure there's a level that makes sense though. If all of the levels either 1) make a sound or pop down over the current view, or 2) show up inconsistently, then it might not make sense to even supply sample code for a notification trigger.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess it's up to the developer even if it makes sounds. Some developers might really want to get feedback 😄

}
}
} else {
Log.w(TAG, "Not listening for screenshots because this activity can't register for permission request results: $activity")
Copy link
Contributor

@lfkellogg lfkellogg Oct 3, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: "Not listening for notification clicks" ?

I'm actually realizing that this logic (and thus my logic from the screenshot detector) is a bit off. If the activity can't get register for an activity result then we'd want to make sure we don't try and request the permission at all. But we're not doing that in either trigger.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've updated the log message.

I've added some code which now checks whether requestPermissionLauncher is null (and sets it to nuill when an activity is paused). I'm now also checking for !hasRequestedPermission before registering the launcher - because if we already have the permission, there's no need for the launcher.

That being said, the logic around requesting permissions seems pretty janky to me. We should probably reword it (for both of our triggers) so it's robust and follows the same pattern. Let's do that after merging this code?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For example, I don't understand why registering the launcher happens in onCreateActivity() instead of in requestPermission() itself.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds good let's have a look. I'd love to put it in some shared component but that goes against the idea of having an entire trigger in one nice copyable file.

But regardless unfortunately you have to register the launcher when the activity is initialized or else vague bad things happen... https://developer.android.com/reference/androidx/activity/result/ActivityResultCaller#registerForActivityResult(androidx.activity.result.contract.ActivityResultContract%3CI,O%3E,androidx.activity.result.ActivityResultCallback%3CO%3E)


private fun requestPermission(activity: Activity) {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.TIRAMISU) {
return // no need
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Before Tiramisu, would ContextCompat.checkSelfPermission() always return PERMISSION_GRANTED? If so then we would never reach this condition.

Even if we could reach this condition we'd just want to go ahead and show the notification, right? As is, we'd do nothing and set hasRequestedPermission to true.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was intended as defense-in-depth, but I can see how it was confusing. So I've changed it.

override fun onActivitySaveInstanceState(activity: Activity, outState: Bundle) {}

fun takeScreenshot() {
val activity = currentActivity
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So it looks like you are able to take a screenshot of a paused activity then, very cool. Out of curiosity, did you try taking a screenshot of the TakeScreenshotAndTriggerFeedbackActivity itself, and if so what happened?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It just took a screenshot of the empty activity.

Comment on lines +28 to +29
versionName "2.0"
versionCode 2
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just checking: do you want to keep this in?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I think we should get into the habit of increasing those numbers.
Adding the feedback functionality seems to enough for a major version bump.

kaibolay and others added 3 commits October 3, 2022 14:38
…/firebase/appdistribution/testapp/NotificationFeedbackTrigger.kt

Co-authored-by: Lee Kellogg <[email protected]>
}
}

class TakeScreenshotAndTriggerFeedbackActivity : AppCompatActivity() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a note: if we're serious about supporting this use case we could add this activity to the SDK (along with tracking the previous activity so we could take the screenshot). Then they could just launch the intent for the activity and we could handle everything else. That might call for an API review though.

@kaibolay kaibolay merged commit cde0818 into fad/in-app-feedback Oct 3, 2022
@kaibolay kaibolay deleted the kb/notification-trigger branch October 3, 2022 21:03
@firebase firebase locked and limited conversation to collaborators Nov 3, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants