@@ -2,15 +2,18 @@ package com.forem.webview
22
33import android.annotation.SuppressLint
44import android.app.Activity
5+ import android.content.ActivityNotFoundException
56import android.content.Intent
67import android.graphics.Bitmap
78import android.net.MailTo
89import android.net.Uri
10+ import android.util.Log
911import android.view.View
1012import android.webkit.CookieManager
1113import android.webkit.WebResourceRequest
1214import android.webkit.WebView
1315import android.webkit.WebViewClient
16+ import android.widget.Toast
1417import androidx.browser.customtabs.CustomTabsIntent
1518import com.google.firebase.messaging.FirebaseMessaging
1619import 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