[英]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.