gpt-3.5-turbo-0301· OpenAI
WildChat-4.8M (AI2)
android webview使用chrome内核
- User
android webview使用chrome内核
- Assistant
Android WebView默认使用的是WebKit内核,但是从Android 7.0开始,可以设置使用Chrome的内核,使用方法如下:
- 首先在应用的build.gradle文件中添加以下依赖:
dependencies { // ... implementation 'com.android.support:customtabs:28.0.0' }- 然后在WebView初始化之前,使用以下代码设置Chrome内核:
WebView webView = new WebView(context); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { webView.setRendererPriorityPolicy(WebView.RENDERER_PRIORITY_BOUND, true); webView.setWebViewClient(new WebViewClient()); boolean result = webView.initialize( context, new WebViewCompatInitializer(), CustomTabsService.REMOTE_BINDING, new ConnectionCallback()); if (!result) { // Fall back to default behavior } }- 最后,在AndroidManifest.xml文件中添加以下代码,以确保使用Chrome定制标签:
<activity android:name="com.google.android.gms.common.api.GoogleApiActivity" android:theme="@android:style/Theme.Translucent.NoTitleBar"/> <service android:name="android.support.customtabs.trusted.LauncherTrustedWebActivityService"> <intent-filter> <action android:name="android.support.customtabs.trusted.TRUSTED_WEB_ACTIVITY_SERVICE_INTERFACE"/> </intent-filter> </service>通过以上步骤可以设置Android WebView使用Chrome的内核。
- User
android6.0 webview使用chrome内核
- Assistant
对于Android 6.0,WebView默认使用的是Chrome 44版本的内核,因此无需特别设置。但是,如果您想使用最新的Chrome内核,可以使用以下方法:
- 在应用的build.gradle文件中添加以下依赖:
dependencies { // ... implementation 'com.android.support:customtabs:26.1.0' }- 然后在WebView初始化之前,使用以下代码设置Chrome内核:
WebView webView = new WebView(context); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { String packageName = context.getPackageName(); WebViewCompat.setDataDirectorySuffix(webView, packageName); }- 最后,在AndroidManifest.xml文件中添加以下代码,以确保使用Chrome定制标签:
<activity android:name="com.google.android.gms.common.api.GoogleApiActivity" android:theme="@android:style/Theme.Translucent.NoTitleBar"/> <service android:name="android.support.customtabs.trusted.LauncherTrustedWebActivityService"> <intent-filter> <action android:name="android.support.customtabs.trusted.TRUSTED_WEB_ACTIVITY_SERVICE_INTERFACE"/> </intent-filter> </service>通过以上步骤可以将Android 6.0的WebView设置为使用最新的Chrome内核。
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.