2

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?

howa.wong
  • 73
  • 3
  • 10

2 Answers2

3

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.

rude
  • 2,340
  • 2
  • 14
  • 19
  • BTW: I've found another topic related to this: http://stackoverflow.com/questions/2645902/can-youtube-be-embedded-in-android-applications-how-about-webos-or-blackberry – rude Oct 22 '10 at 08:49
1
mWebView.loadUrl(url);

if (url.contains("rtsp")) {
     Uri uri = Uri.parse(url);
     Intent intent = new Intent(Intent.ACTION_VIEW, uri);
     startActivity(intent);
}
Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343
lancha90
  • 5,064
  • 2
  • 17
  • 9