问题描述
我写了一个应用程序与web视图用于显示m.youtube.com。它工作在其他Android版本。点击:但是,在Android 2.2系统,shouldOverrideUrlLoading甚至没有像//vx.cache.youtube.com / RTSP ...链接时调用。有没有人有同样的问题?
I wrote an app with webview which displays m.youtube.com. It works in other android versions. However, in Android 2.2, shouldOverrideUrlLoading is not even called when a link like "rtsp://vx.cache.youtube.com/..." is clicked. Does anyone have the same problem?
推荐答案
我发现了这个问题的解决方法。
I've found a workaround for this problem.
如果您将更改的WebView的用户代理同时要求YouTube页面(),你会得到正确的链接到视频。和所有视频将YouYube内部应用程序中打开。
If you'll change the User-Agent of WebView while requesting YouTube page (http://m.youtube.com/) you'll get correct links to the videos. And all videos will be opened by YouYube internal application.
下面一点code片断:
Here is little code snippet:
final String url = "http://m.youtube.com/#/watch?xl=xl_blazer&v=osc8Gvz40C4";
final WebView viewWeb = new WebView(this);
viewWeb.getSettings().setJavaScriptEnabled(true);
String userAgent = viewWeb.getSettings().getUserAgentString();
userAgent = userAgent.replace("Android 2.2", "Android 2.1");
viewWeb.getSettings().setUserAgentString(userAgent);
viewWeb.loadUrl(url);
这是一个有点棘手,但它的工作原理。期待找到一个修复,但不是一个解决办法。
It is a little tricky but it works. Looking forward to find a fix but not a workaround.
这篇关于的Android 2.2的WebView和WebViewClient RTSP问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!