Android Bug记录–WebView UserAgent

  • A+

错误日志:

同一段代码在原本的demo中使用没有问题,但是移植到项目中就报上述错误,即使加上了try~catch(Exception)也不能起作用。

查阅文档:http://developer.android.com/intl/zh-cn/guide/webapps/migrating.html
原来,在4.4之后就不能在主线程new Webview(ctx)了,不过文档中提供的方法:

If you need to retrieve the user agent but don't need to store it for your app or do not want to instantiate WebView, you should use the static method, getDefaultUserAgent(). However, if you intend to override the user agent string in your WebView, you may instead want to use getUserAgentString().

于是,原本的代码new WebView(context).getSettings().getUserAgentString()修改为:

weinxin
我的微信公众号
我的微信公众号扫一扫
Liu, Thinkin

发表评论

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: