Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ androidx-navigation-runtime = { module = "androidx.navigation:navigation-runtime
androidx-navigation-compose = { module = "androidx.navigation:navigation-compose", version.ref = "androidxNavigation" }
androidx-sqlite = { module = "androidx.sqlite:sqlite", version = "2.5.2" }
androidx-recyclerview = { module = "androidx.recyclerview:recyclerview", version = "1.2.1" }
androidx-browser = { module = "androidx.browser:browser", version = "1.8.0" }
coil-compose = { module = "io.coil-kt:coil-compose", version = "2.6.0" }
commons-compress = {module = "org.apache.commons:commons-compress", version = "1.25.0"}
context-propagation = { module = "io.micrometer:context-propagation", version = "1.1.0" }
Expand Down
1 change: 1 addition & 0 deletions sentry-samples/sentry-samples-android/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ dependencies {
implementation(libs.androidx.compose.material3)
implementation(libs.androidx.navigation.compose)
implementation(libs.androidx.recyclerview)
implementation(libs.androidx.browser)
implementation(libs.coil.compose)
implementation(libs.kotlinx.coroutines.android)
implementation(libs.retrofit)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,12 @@
android:exported="false" />

<activity
android:name=".compose.ComposeActivity"
android:exported="false" />
android:name=".CustomTabsActivity"
android:exported="false" />

<activity
android:name=".compose.ComposeActivity"
android:exported="false" />

<activity android:name=".FrameDataForSpansActivity"
android:exported="false"/>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package io.sentry.samples.android;

import android.net.Uri;
import android.os.Bundle;
import androidx.appcompat.app.AppCompatActivity;
import androidx.browser.customtabs.CustomTabColorSchemeParams;
import androidx.browser.customtabs.CustomTabsIntent;
import androidx.core.content.ContextCompat;

public class CustomTabsActivity extends AppCompatActivity {

private static final String DEMO_URL = "https://www.sentry.io/";

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);

CustomTabsIntent.Builder builder = new CustomTabsIntent.Builder();

CustomTabColorSchemeParams params =
new CustomTabColorSchemeParams.Builder()
.setToolbarColor(ContextCompat.getColor(this, R.color.colorPrimary))
.build();
builder.setDefaultColorSchemeParams(params);

builder.setShowTitle(true);
builder.setShareState(CustomTabsIntent.SHARE_STATE_ON);
builder.setInstantAppsEnabled(true);

CustomTabsIntent customTabsIntent = builder.build();
customTabsIntent.launchUrl(this, Uri.parse(DEMO_URL));

Choose a reason for hiding this comment

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

Potential bug: The call to customTabsIntent.launchUrl() is not wrapped in a try-catch block, which will cause a crash if no suitable browser is found.
  • Description: The call to customTabsIntent.launchUrl() is not wrapped in a try-catch block to handle ActivityNotFoundException. This exception will be thrown, causing the app to crash, under a few conditions. On devices running Android 11 (API 30) or newer, the crash will occur because the AndroidManifest.xml file is missing the required &lt;queries&gt; element, which prevents the app from discovering installed browsers. The crash can also happen on any Android version if the device has no browser installed or if the installed browsers do not support Custom Tabs. Past Sentry issues (1, 2) confirm ActivityNotFoundException is a recurring problem.

  • Suggested fix: Wrap the customTabsIntent.launchUrl() call in a try-catch block to handle ActivityNotFoundException. In the catch block, you can fall back to a standard ACTION_VIEW intent or show an error message. Additionally, add the appropriate &lt;queries&gt; element to AndroidManifest.xml to ensure browser visibility on Android 11+ devices.
    severity: 0.85, confidence: 0.95

Did we get this right? 👍 / 👎 to inform future reviews.


finish();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,11 @@ public void run() {
startActivity(new Intent(this, ProfilingActivity.class));
});

binding.openCustomTabsActivity.setOnClickListener(
view -> {
startActivity(new Intent(this, CustomTabsActivity.class));
});

binding.openFrameDataForSpans.setOnClickListener(
view -> startActivity(new Intent(this, FrameDataForSpansActivity.class)));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,13 @@
android:layout_height="wrap_content"
android:text="@string/open_profiling_activity"/>

<Button
android:id="@+id/open_custom_tabs_activity"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/open_custom_tabs_activity"
/>

<Button
android:id="@+id/open_frame_data_for_spans"
android:layout_width="wrap_content"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
<string name="open_permissions_activity">Open Permissions Activity</string>
<string name="open_compose_activity">Open Compose Activity</string>
<string name="open_profiling_activity">Open Profiling Activity</string>
<string name="open_custom_tabs_activity">Open Custom Tabs Activity</string>
<string name="open_frame_data_for_spans">Open Frame Data for Spans Activity</string>
<string name="open_metrics">Delightful Developer Metrics</string>
<string name="test_timber_integration">Test Timber</string>
Expand Down
Loading