android 2.2 WebView and WebViewClient RTSP problem

廉价感情. 提交于 2019-12-11 02:11:40

问题


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?


回答1:


I've found a workaround for this problem.

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 YouTube internal application.

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.




回答2:


mWebView.loadUrl(url);

if (url.contains("rtsp")) {
     Uri uri = Uri.parse(url);
     Intent intent = new Intent(Intent.ACTION_VIEW, uri);
     startActivity(intent);
}


来源:https://stackoverflow.com/questions/3304678/android-2-2-webview-and-webviewclient-rtsp-problem

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!