Skip to content

Commit f778c76

Browse files
committed
Added exceptions to openCustomTab function
1 parent 1c1341c commit f778c76

1 file changed

Lines changed: 16 additions & 3 deletions

File tree

foremwebview/src/main/java/com/forem/webview/ForemWebViewClient.kt

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,18 @@ package com.forem.webview
22

33
import android.annotation.SuppressLint
44
import android.app.Activity
5+
import android.content.ActivityNotFoundException
56
import android.content.Intent
67
import android.graphics.Bitmap
78
import android.net.MailTo
89
import android.net.Uri
10+
import android.util.Log
911
import android.view.View
1012
import android.webkit.CookieManager
1113
import android.webkit.WebResourceRequest
1214
import android.webkit.WebView
1315
import android.webkit.WebViewClient
16+
import android.widget.Toast
1417
import androidx.browser.customtabs.CustomTabsIntent
1518
import com.google.firebase.messaging.FirebaseMessaging
1619
import com.google.gson.Gson
@@ -267,9 +270,19 @@ class ForemWebViewClient(
267270

268271
private fun openCustomTab(url: String) {
269272
if (activity != null) {
270-
CustomTabsIntent.Builder()
271-
.build()
272-
.also { it.launchUrl(activity, Uri.parse(url)) }
273+
try {
274+
val customTabIntent = CustomTabsIntent.Builder().build()
275+
customTabIntent.launchUrl(activity, Uri.parse(url))
276+
} catch (e: ActivityNotFoundException) {
277+
Toast.makeText(activity, "Unable to open custom tab", Toast.LENGTH_SHORT).show()
278+
Log.e("ForemWebViewClient", "openCustomTab: ActivityNotFoundException", e)
279+
} catch (e: SecurityException) {
280+
Toast.makeText(activity, "Unable to open custom tab", Toast.LENGTH_SHORT).show()
281+
Log.e("ForemWebViewClient", "openCustomTab: SecurityException", e)
282+
} catch (e: Exception) {
283+
Toast.makeText(activity, "Unable to open custom tab", Toast.LENGTH_SHORT).show()
284+
Log.e("ForemWebViewClient", "openCustomTab: Exception", e)
285+
}
273286
}
274287
}
275288

0 commit comments

Comments
 (0)