@@ -24,6 +24,8 @@ package com.theupnextapp.ui.traktAccount
2424import android.app.Activity
2525import android.content.Context
2626import android.content.Intent
27+ import android.content.pm.PackageManager
28+ import android.widget.Toast
2729import androidx.browser.customtabs.CustomTabsIntent
2830import androidx.compose.foundation.ExperimentalFoundationApi
2931import androidx.compose.foundation.Image
@@ -170,7 +172,7 @@ private fun DisconnectTraktDialog(
170172}
171173
172174fun openCustomTab (context : Context ) {
173- val packageName = " com.android.chrome"
175+ val packageName = " com.android.chrome" // This is the specific package causing the issue
174176
175177 val traktUrl =
176178 " https://trakt.tv/oauth/authorize?response_type=code&client_id=" +
@@ -185,12 +187,26 @@ fun openCustomTab(context: Context) {
185187
186188 val customBuilder = builder.build()
187189
188- if (packageName != null ) {
190+ // Check if Chrome is available
191+ val chromePackageInfo = try {
192+ context.packageManager.getPackageInfo(packageName, 0 )
193+ } catch (e: PackageManager .NameNotFoundException ) {
194+ null
195+ }
196+
197+ if (chromePackageInfo != null ) {
198+ // If Chrome is found
189199 customBuilder.intent.setPackage(packageName)
190200 customBuilder.launchUrl(context, traktUrl.toUri())
191201 } else {
202+ // Fallback to any browser if Chrome is not found
192203 val intent = Intent (Intent .ACTION_VIEW , traktUrl.toUri())
193- activity?.startActivity(intent)
204+ // Ensure there's an activity to handle this intent to prevent another crash
205+ if (intent.resolveActivity(context.packageManager) != null ) {
206+ activity?.startActivity(intent)
207+ } else {
208+ Toast .makeText(context, " No browser found" , Toast .LENGTH_SHORT ).show()
209+ }
194210 }
195211}
196212
0 commit comments