[英]Check which url is opened in custom chrome tabs
chrome 自定义选项卡中是否有类似于 Webview 的 onPageStarted 的任何功能。 在 onNavigation 中 .. 捆绑包始终为空
根据设计,Chrome 自定义标签无法做到这一点。 您可以判断用户已经导航,但无法判断他们去了哪里。 有关可能的详细信息,请参阅: http : //developer.android.com/reference/android/support/customtabs/CustomTabsCallback.html 。
如果您可以通过单击工具栏操作按钮或菜单选项让用户触发 PendingIntent,则您可以查看 Chrome 自定义标签中当前打开的 URL。
在您的片段/活动中,创建一个嵌套的 BroadcastReceiver 类,该类将在其 onReceive() 方法中处理传入的意图:
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())
}
}
}
将接收器添加到您的清单文件中:
<receiver
android:name=".ui.dig.DigTabs$DigBroadcastReceiver"
android:enabled="true" />
创建 PendingIntent 并将其添加到您的 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))
请参阅我在 Medium 上对此进行解释的文章。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.