fun webViewEnabled(): Boolean {
return try {
CookieManager.getInstance()
true
} catch (e: Exception) {
false
}
}
val hasWebView: Boolean = kotlin.runCatching { CookieManager.getInstance() }.isSuccess
它的原理是如果WebView不可用,那么CookieManager.getInstance()将抛出AndroidRuntimeException异常。
getPackageManager().hasSystemFeature("android.software.webview")不是很可靠。如果设备应该有一个webview,但在系统设置中已禁用,则它将返回true。
我在华为P20上进行了测试,方法是前往 设置 -> 应用程序 -> 安卓系统 WebView -> 禁用。
https://www.techesi.com/zh-CN/what-is-android-system-webview-1.html

1万+

被折叠的 条评论
为什么被折叠?



