gpt4 book ai didi

android - 如何查看 Chrome 是否支持 Chrome 自定义标签页?

转载 作者:塔克拉玛干 更新时间:2023-11-02 08:18:19 30 4
gpt4 key购买 nike

我有一个 Activity 将外部 url 加载到我的应用程序中的 webview 中。我想在可用时使用 Chrome 自定义选项卡,但我支持的设备可能没有支持它们的 Chrome 版本。

在不支持 CustomTabs 的情况下,我想使用我的旧代码,但在支持时使用 CustomTabsIntent.Builder()。旧代码加载 WebView 中的内容,该 WebView 包含在 Activity 中,我仍然可以在其中管理 ActionBar。

我想编写一个辅助方法来告诉我它是否受支持,但我不确定如何支持。开发者页面上的信息非常少: https://developer.chrome.com/multidevice/android/customtabs

它表示如果您绑定(bind)成功,则可以安全地使用自定义选项卡。有没有简单的方法来绑定(bind)来测试这个?

我假设是这样的:

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
}

最佳答案

您可以使用 PackageManager 检查是否支持自定义选项卡,而不是绑定(bind)和取消绑定(bind)服务。

  private static final String SERVICE_ACTION = "android.support.customtabs.action.CustomTabsService";
private static final String CHROME_PACKAGE = "com.android.chrome";

private static boolean isChromeCustomTabsSupported(@NonNull final Context context) {
Intent serviceIntent = new Intent(SERVICE_ACTION);
serviceIntent.setPackage(CHROME_PACKAGE);
List<ResolveInfo> resolveInfos = context.getPackageManager().queryIntentServices(serviceIntent, 0);
return !(resolveInfos == null || resolveInfos.isEmpty());
}

请注意,其他浏览器将来可能会支持自定义选项卡,因此您可能需要对其进行修改以支持这种情况。

关于android - 如何查看 Chrome 是否支持 Chrome 自定义标签页?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32974433/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com