问题
I know that this question has been answered many times, but I still can't get it to work on Android 2.2 nor 2.3.
I am developing an app which is composed of tabs. One of those tabs loads the mobile version of YouTube inside a WebView. So far so good.
The problem is that the videos don't play inside a WebView, so I'm using the YouTube app as here is suggested. Great! It works in Android 2.1, but not in 2.3. All the phones that I'm using have the YouTube app instaled. It simply doesn't display the window that let the user choose the YouTube App or the browser. Any suggestion? Here is my onCreate
method:
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.website);
this.webView = (WebView) findViewById(R.id.webview);
this.webView.setWebViewClient(new WebViewClient() {
public boolean shouldOverrideUrlLoading(WebView view, String url) {
// YouTube video link
if (url.startsWith("vnd.youtube:")) {
int n = url.indexOf("?");
if (n > 0) {
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(String.format("http://www.youtube.com/v/%s", url.substring("vnd.youtube:".length(),n)))));
}
return true;
}
return false;
}
});
WebSettings webSettings = this.webView.getSettings();
webSettings.setJavaScriptEnabled(true);
this.webView.loadUrl("http://m.youtube.com/");
}
Thanks in advance.
回答1:
It's like the Twitter problem, and I solved it in a dirty way.
来源:https://stackoverflow.com/questions/11215443/android-2-2-2-3-doesnt-load-youtube-videos-on-the-youtube-app-from-a-webview