Skip to content

Commit df24d81

Browse files
markushilizokm
andauthored
feat(android): Add docs for screenshots/vh BeforeCaptureCallback (#7239)
Co-authored-by: Liza Mock <[email protected]>
1 parent fd03a1d commit df24d81

File tree

2 files changed

+110
-0
lines changed

2 files changed

+110
-0
lines changed

src/platform-includes/enriching-events/attach-screenshots/android.mdx

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,57 @@
33
<meta-data android:name="io.sentry.attach-screenshot" android:value="true" />
44
</application>
55
```
6+
7+
### Customize Screenshot Capturing
8+
9+
<Note>
10+
11+
Requires SDK version `6.24.0` or higher.
12+
13+
</Note>
14+
15+
Because capturing screenshots can be a resource-intensive operation on Android, it's limited to one screenshot every 2 seconds using a debouncing mechanism. This behavior can be overruled if you supply a `BeforeCaptureCallback` for screenshots in the `SentryAndroidOptions`.
16+
17+
The `BeforeCaptureCallback` also allows you to customize the behavior based on event data, so you can decide when to capture a screenshot and when not to. For example, you can decide to only capture screenshots of crashed and fatal events:
18+
19+
```java
20+
import io.sentry.android.core.SentryAndroid;
21+
22+
SentryAndroid.init(this, options -> {
23+
options.setBeforeScreenshotCaptureCallback((event, hint, debounce) -> {
24+
// always capture crashed events
25+
if (event.isCrashed()) {
26+
return true;
27+
}
28+
29+
// if debounce is active, skip capturing
30+
if (debounce) {
31+
return false;
32+
} else {
33+
// also capture fatal events
34+
return event.getLevel() == SentryLevel.FATAL;
35+
}
36+
});
37+
});
38+
```
39+
40+
```kotlin
41+
import io.sentry.android.core.SentryAndroid
42+
43+
SentryAndroid.init(this) { options ->
44+
options.setBeforeScreenshotCaptureCallback { event, hint, debounce ->
45+
// always capture crashed events
46+
if (event.isCrashed) {
47+
return@setBeforeScreenshotCaptureCallback true
48+
}
49+
50+
// if debounce is active, skip capturing
51+
if (debounce) {
52+
return@setBeforeScreenshotCaptureCallback false
53+
} else {
54+
// also capture fatal events
55+
return@setBeforeScreenshotCaptureCallback event.level == SentryLevel.FATAL
56+
}
57+
}
58+
}
59+
```

src/platform-includes/enriching-events/attach-viewhierarchy/android.mdx

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,62 @@
44
</application>
55
```
66

7+
### Customize View Hierarchy Capturing
8+
9+
<Note>
10+
11+
Requires SDK version `6.24.0` or higher.
12+
13+
</Note>
14+
15+
Because capturing view hierarchy can be a resource-intensive operation on Android, it's limited to one view hierarchy every 2 seconds using a debouncing mechanism. This behavior can be overruled if you supply a `BeforeCaptureCallback` for view hierarchies in the `SentryAndroidOptions`.
16+
17+
The `BeforeCaptureCallback` also allows you to customize behavior based on event data so you can decide when to capture view hierarchy and when not to. For example, you can decide to only capture view hierarchy for crashed and fatal events:
18+
19+
```java
20+
import io.sentry.SentryLevel;
21+
import io.sentry.android.core.SentryAndroid;
22+
23+
SentryAndroid.init(this, options -> {
24+
options.setBeforeViewHierarchyCaptureCallback((event, hint, debounce) -> {
25+
// always capture crashed events
26+
if (event.isCrashed()) {
27+
return true;
28+
}
29+
30+
// if debounce is active, skip capturing
31+
if (debounce) {
32+
return false;
33+
} else {
34+
// also capture fatal events
35+
return event.getLevel() == SentryLevel.FATAL;
36+
}
37+
});
38+
});
39+
```
40+
41+
```kotlin
42+
import io.sentry.SentryLevel
43+
import io.sentry.android.core.SentryAndroid
44+
45+
SentryAndroid.init(this) { options ->
46+
options.setBeforeViewHierarchyCaptureCallback { event, hint, debounce ->
47+
// always capture crashed events
48+
if (event.isCrashed) {
49+
return@setBeforeScreenshotCaptureCallback true
50+
}
51+
52+
// if debounce is active, skip capturing
53+
if (debounce) {
54+
return@setBeforeScreenshotCaptureCallback false
55+
} else {
56+
// also capture fatal events
57+
return@setBeforeScreenshotCaptureCallback event.level == SentryLevel.FATAL
58+
}
59+
}
60+
}
61+
```
62+
763
### Jetpack Compose Support using the Sentry Kotlin Compiler Plugin
864

965
<Note>

0 commit comments

Comments
 (0)