Check which url is opened in custom chrome tabs
By design this is not possible with Chrome Custom Tabs. You can tell that a user has navigated but you can't tell where they've gone to. See: http://developer.android.com/reference/android/support/customtabs/CustomTabsCallback.html for details of what's possible.
You can see what URL is currently open in Chrome Custom Tabs if you can get the user to trigger a PendingIntent by clicking on a toolbar action button or a menu option.
In your fragment/activity, create a nested BroadcastReceiver class that will handle the incoming intent in it's onReceive() method:
class DigBroadcastReceiver() : BroadcastReceiver() { override fun onReceive(context: Context, intent: Intent) { val uri: Uri? = intent.data if (uri != null) { Log.d("Broadcast URL",uri.toString()) main.genericToast(uri.toString()) } }}
Add the receiver to your manifest file:
<receiver android:name=".ui.dig.DigTabs$DigBroadcastReceiver" android:enabled="true" />
Create the PendingIntent and add it to your CustomTabsIntent.Builder:
val sendLinkIntent = Intent(main,DigBroadcastReceiver()::class.java) sendLinkIntent.putExtra(Intent.EXTRA_SUBJECT,"This is the link you were exploring") val pendingIntent = PendingIntent.getBroadcast(main,0,sendLinkIntent,PendingIntent.FLAG_UPDATE_CURRENT) // Set the action button AppCompatResources.getDrawable(main, R.drawable.close_icon)?.let { DrawableCompat.setTint(it, Color.WHITE) builder.setActionButton(it.toBitmap(),"Add this link to your dig",pendingIntent,false) } val customTabsIntent: CustomTabsIntent = builder.build() customTabsIntent.launchUrl(main, Uri.parse(url))