Chrome自定义选项卡中是否有类似于Webview的onPageStarted的任何功能。 IN onNavigation ..包总是空的
答案 0 :(得分:3)
根据设计,Chrome自定义标签无法实现。您可以告诉用户已导航但您无法分辨他们去过哪里。请参阅:http://developer.android.com/reference/android/support/customtabs/CustomTabsCallback.html了解可能的详细信息。
答案 1 :(得分:0)
如果您可以通过单击工具栏上的操作按钮或菜单选项来使用户触发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))