Skip to content

Commit 604a261

Browse files
runningcodeclaude
andauthored
feat(android-distribution): Add update check button to Android sample (#4764)
- Add sentry-android-distribution as debug-only dependency - Add "Check for Update" button to main activity UI - Implement handler that calls Sentry.distribution().checkForUpdate() - Handle all UpdateStatus types: NewRelease, UpToDate, NoNetwork, UpdateError - Display results in toast messages Note: This feature requires proper distribution tokens and configuration to work. This change makes it easier to test the distribution integration. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-authored-by: Claude <noreply@anthropic.com>
1 parent 806307f commit 604a261

File tree

4 files changed

+44
-0
lines changed

4 files changed

+44
-0
lines changed

sentry-samples/sentry-samples-android/build.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,7 @@ dependencies {
150150
implementation(libs.sentry.native.ndk)
151151
implementation(libs.timber)
152152

153+
debugImplementation(projects.sentryAndroidDistribution)
153154
debugImplementation(libs.leakcanary)
154155
}
155156

sentry-samples/sentry-samples-android/src/main/java/io/sentry/samples/android/MainActivity.java

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,14 @@
55
import android.content.res.Configuration;
66
import android.os.Bundle;
77
import android.os.Handler;
8+
import android.widget.Toast;
89
import androidx.appcompat.app.AlertDialog;
910
import androidx.appcompat.app.AppCompatActivity;
1011
import io.sentry.Attachment;
1112
import io.sentry.ISpan;
1213
import io.sentry.MeasurementUnit;
1314
import io.sentry.Sentry;
15+
import io.sentry.UpdateStatus;
1416
import io.sentry.instrumentation.file.SentryFileOutputStream;
1517
import io.sentry.protocol.Feedback;
1618
import io.sentry.protocol.User;
@@ -304,6 +306,40 @@ public void run() {
304306
Sentry.replay().enableDebugMaskingOverlay();
305307
});
306308

309+
binding.checkForUpdate.setOnClickListener(
310+
view -> {
311+
Toast.makeText(this, "Checking for updates...", Toast.LENGTH_SHORT).show();
312+
Sentry.distribution()
313+
.checkForUpdate(
314+
result -> {
315+
runOnUiThread(
316+
() -> {
317+
String message;
318+
if (result instanceof UpdateStatus.NewRelease) {
319+
UpdateStatus.NewRelease newRelease = (UpdateStatus.NewRelease) result;
320+
message =
321+
"Update available: "
322+
+ newRelease.getInfo().getBuildVersion()
323+
+ " (Build "
324+
+ newRelease.getInfo().getBuildNumber()
325+
+ ")\nDownload URL: "
326+
+ newRelease.getInfo().getDownloadUrl();
327+
} else if (result instanceof UpdateStatus.UpToDate) {
328+
message = "App is up to date!";
329+
} else if (result instanceof UpdateStatus.NoNetwork) {
330+
UpdateStatus.NoNetwork noNetwork = (UpdateStatus.NoNetwork) result;
331+
message = "No network connection: " + noNetwork.getMessage();
332+
} else if (result instanceof UpdateStatus.UpdateError) {
333+
UpdateStatus.UpdateError error = (UpdateStatus.UpdateError) result;
334+
message = "Error checking for updates: " + error.getMessage();
335+
} else {
336+
message = "Unknown status";
337+
}
338+
Toast.makeText(this, message, Toast.LENGTH_LONG).show();
339+
});
340+
});
341+
});
342+
307343
setContentView(binding.getRoot());
308344
}
309345

sentry-samples/sentry-samples-android/src/main/res/layout/activity_main.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,12 @@
170170
android:layout_height="wrap_content"
171171
android:text="@string/enable_replay_debug_mode"/>
172172

173+
<Button
174+
android:id="@+id/check_for_update"
175+
android:layout_width="wrap_content"
176+
android:layout_height="wrap_content"
177+
android:text="@string/check_for_update"/>
178+
173179
</LinearLayout>
174180

175181
</ScrollView>

sentry-samples/sentry-samples-android/src/main/res/values/strings.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
<string name="throw_in_coroutine">Throw exception in coroutine</string>
3030
<string name="enable_replay_debug_mode">Enable Replay Debug Mode</string>
3131
<string name="show_dialog">Show Dialog</string>
32+
<string name="check_for_update">Check for Update</string>
3233
<string name="back_main">Back to Main Activity</string>
3334
<string name="tap_me">text</string>
3435
<string name="lipsum">Lorem ipsum dolor sit amet, consectetur adipiscing elit. Proin nibh lorem, venenatis sed nulla vel, venenatis sodales augue. Mauris varius elit eu ligula volutpat, sed tincidunt orci porttitor. Donec et dignissim lacus, sed luctus ipsum. Praesent ornare luctus tortor sit amet ultricies. Cras iaculis et diam et vulputate. Cras ut iaculis mauris, non pellentesque diam. Nunc in laoreet diam, vitae accumsan eros. Morbi non nunc ac eros molestie placerat vitae id dolor. Quisque ornare aliquam ipsum, a dapibus tortor. In eu sodales tellus.

0 commit comments

Comments
 (0)