我有一個活動,將外部網址加載到我的應用內的網頁視圖中。我希望在可用時使用Chrome自定義標籤,但我支持的設備可能沒有支持它們的Chrome版本。如何檢查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
}
此檢查是否在其他瀏覽器中支持Chrome自定義選項卡? – X09