我有一个将外部 url 加载到我的应用程序中的 web 视图中的活动。我想在 Chrome 自定义标签可用时使用它,但我支持的设备可能没有支持它们的 Chrome 版本。
在不支持 CustomTabs 的情况下,我想使用我的旧代码,但在支持时使用 CustomTabsIntent.Builder()。旧代码将内容加载到 Activity 中包含的 WebView 中,我仍然可以在其中管理 ActionBar。
我想写一个帮助方法,它会告诉我它是否受支持,但我不确定如何。开发者页面上的信息非常少: https ://developer.chrome.com/multidevice/android/customtabs
它说如果您绑定成功,则可以安全地使用自定义选项卡。有没有一种简单的方法来绑定来测试这个?
像这样我假设:
Intent serviceIntent = new Intent("android.support.customtabs.action.CustomTabsService");
serviceIntent.setPackage("com.android.chrome");
boolean customTabsSupported = bindService(serviceIntent, new CustomTabsServiceConnection() {
@Override
public void onCustomTabsServiceConnected(final ComponentName componentName, final CustomTabsClient customTabsClient) {}
@Override
public void onServiceDisconnected(final ComponentName name) {}
},
Context.BIND_AUTO_CREATE | Context.BIND_WAIVE_PRIORITY);
if (customTabsSupported) {
// is supported
}