Skip to content

feat(feedback): Add screenshot attachment button to user feedback widget - #5828

Open
markushi wants to merge 10 commits into
mainfrom
feat/feedback-screenshot-attachment
Open

feat(feedback): Add screenshot attachment button to user feedback widget#5828
markushi wants to merge 10 commits into
mainfrom
feat/feedback-screenshot-attachment

Conversation

@markushi

@markushimarkushi commented Jul 23, 2026

Copy link
Copy Markdown
Member

📜 Description

Adds an "Add a screenshot" button to the Android user feedback form that opens the
androidx photo picker (ActivityResultContracts.PickVisualMedia, images only) and sends
the picked image as an attachment in the same envelope as the feedback.

Screen_recording_20260723_183244.mp4
image
  • New SentryFeedbackOptions: enableScreenshot (default true, matching the JS SDK),
    addScreenshotButtonLabel, removeScreenshotButtonLabel, plus the
    io.sentry.feedback.enable-screenshot manifest flag
  • androidx.activity:activity:1.8.2 is added as compileOnly — no new transitive
    dependency; the button is hidden (with a warning log) when androidx.activity is missing
    or the host Activity is not a ComponentActivity
  • The image is size-checked against maxAttachmentSize at pick time

💡 Motivation and Context

💚 How did you test it?

Unit tests + Manual testing.

📝 Checklist

  • I added GH Issue ID & Linear ID
  • I added tests to verify the changes.
  • No new PII added or SDK only sends newly added PII if sendDefaultPII is enabled.
  • I updated the docs if needed.
  • I updated the wizard if needed.
  • Review from the native team if needed.
  • No breaking change or entry added to the changelog.
  • No breaking change for hybrid SDKs or communicated to hybrid SDKs.
  • Public API changes reviewed by another Mobile SDK team member or implemented according to the develop docs spec.

@linear-code

Copy link
Copy Markdown

JAVA-538

@github-actions

github-actionsBot commented Jul 23, 2026

Copy link
Copy Markdown
Contributor
Messages
📖Do not forget to update Sentry-docs with your feature once the pull request gets approved.

Generated by 🚫 dangerJS against c8c08c1

@sentry

sentryBot commented Jul 23, 2026

Copy link
Copy Markdown

📲 Install Builds

Android

🔗 App NameApp IDVersionConfiguration
SDK Sizeio.sentry.tests.size8.50.0 (1)release

⚙️ sentry-android Build Distribution Settings

@github-actions

github-actionsBot commented Jul 23, 2026

Copy link
Copy Markdown
Contributor

Performance metrics 🚀

PlainWith SentryDiff
Startup time313.69 ms370.22 ms56.54 ms
Size0 B0 B0 B

Baseline results on branch: main

Startup times

RevisionPlainWith SentryDiff
22f4345307.87 ms354.51 ms46.64 ms
8c7718c307.42 ms374.84 ms67.42 ms
bb0ff41321.00 ms378.28 ms57.28 ms
c8125f3397.65 ms485.14 ms87.49 ms
eb95ded317.51 ms369.08 ms51.57 ms
f634d01375.06 ms420.04 ms44.98 ms
9fbb112359.71 ms421.85 ms62.14 ms
d501a7e307.33 ms341.94 ms34.61 ms
bb0ff41317.76 ms384.66 ms66.90 ms
9054d65330.94 ms403.24 ms72.30 ms

App size

RevisionPlainWith SentryDiff
22f43451.58 MiB2.29 MiB719.83 KiB
8c7718c0 B0 B0 B
bb0ff410 B0 B0 B
c8125f31.58 MiB2.10 MiB532.32 KiB
eb95ded0 B0 B0 B
f634d011.58 MiB2.10 MiB533.40 KiB
9fbb1121.58 MiB2.11 MiB539.18 KiB
d501a7e0 B0 B0 B
bb0ff410 B0 B0 B
9054d651.58 MiB2.29 MiB723.38 KiB

Previous results on branch: feat/feedback-screenshot-attachment

Startup times

RevisionPlainWith SentryDiff
86e5409326.20 ms351.31 ms25.11 ms
676848b367.87 ms443.02 ms75.15 ms
37c6869327.68 ms381.06 ms53.38 ms

App size

RevisionPlainWith SentryDiff
86e54090 B0 B0 B
676848b0 B0 B0 B
37c68690 B0 B0 B

@markushi
markushi marked this pull request as ready for review July 23, 2026 17:27
Comment threadsentry/src/main/java/io/sentry/util/FileUtils.java
Comment threadsentry/src/main/java/io/sentry/util/FileUtils.java Outdated

@runningcoderunningcode left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks for adding this!

mime,
"event.attachment",
false));
} catch (Throwable t) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I decided I'm always going to comment whenever we add new usages of this. Sorry to bring it up again.

  1. How will we know that this feature is working in production if we swallow all errors?
  2. Since we're dealing with images, files and attachments how we we know we aren't swallowing a permissions issue or OOM?

return cursor.getLong(sizeIndex);
}
}
} catch (Throwable ignored) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

same comment here as above.

Comment threadsentry/src/main/java/io/sentry/util/FileUtils.java Outdated
Comment threadsentry-android-core/build.gradle.kts
Comment threadsentry/src/main/java/io/sentry/SentryFeedbackOptions.java Outdated
Comment threadsentry/src/main/java/io/sentry/SentryFeedbackOptions.java Outdated
Use term "screenshot" everywhere
Improve nullability handling

@cursorcursorBot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit c8c08c1. Configure here.

"screenshot." + ext,
mime,
"event.attachment",
false));

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Lazy URI read may drop attachment

Medium Severity

The screenshot Attachment uses a lazy byteProvider that opens the photo-picker Uri later on the async transport/cache path. Picker URIs only grant temporary read access to the host activity, so if that access is gone before serialization, the attachment is dropped while feedback still reports success.

Additional Locations (1)
Fix in CursorFix in Web

Reviewed by Cursor Bugbot for commit c8c08c1. Configure here.

Comment on lines +415 to +418
.log(
SentryLevel.WARNING,
"Feedback screenshot button won't be shown. It requires the androidx.activity "
+ "dependency and the feedback form being shown from a ComponentActivity.");

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Bug: The maybeRegisterScreenshotPicker method lacks a guard to prevent re-registering the screenshot picker, which could cause a crash if onStart() is called multiple times.
Severity: MEDIUM

Suggested Fix

In maybeRegisterScreenshotPicker, add a null check to ensure screenshotPicker is not already initialized before calling SentryFeedbackScreenshotPicker.register(). For example: if (screenshotPicker == null) { ... }.

Prompt for AI Agent
Review the code at the location below. A potential bug has been identified by an AI
agent. Verify if this is a real issue. If it is, propose a fix; if not, explain why it's
not valid.
Location:
sentry-android-core/src/main/java/io/sentry/android/core/SentryUserFeedbackForm.java#L415-L418
Potential issue: In `SentryUserFeedbackForm`, the `maybeRegisterScreenshotPicker` method
is called from `onStart()` to register an activity result launcher. This registration
uses a hardcoded key. The method lacks a defensive check to see if the
`screenshotPicker` has already been initialized. While the `onStop()` method unregisters
the launcher, it's possible in certain edge-case lifecycle scenarios for `onStart()` to
be invoked twice without an intervening `onStop()`. This would lead to an attempt to
register the same key again, causing an `IllegalStateException` and crashing the app.

Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add file attachment support to user feedback widget

2 participants

@markushi@runningcode