的Andr​​oid 2.2 / 2.3不从的WebView上的YouTube应用加载YouTube视频 [英] Android 2.2/2.3 doesn't load YouTube videos on the YouTube app from a WebView

查看:318
本文介绍了的Andr​​oid 2.2 / 2.3不从的WebView上的YouTube应用加载YouTube视频的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道这个问题已经回答了很多次,但我仍然无法得到它在Android 2.2,也没有2.3的工作。

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.

我正在开发由标签页的应用程序。其中一个标签加载YouTube上的的WebView内的移动版本。到目前为止好。

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.

问题是,视频没有一个的WebView打内线,所以我这里使用YouTube应用建议。大!它工作在Android 2.1系统,但不是在2.3。我使用有YouTube应用中的所有手机instaled。它根本不显示让用户选择YouTube应用或浏览器窗口。任何建议?这里是我的的onCreate 方法:

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/");
}

先谢谢了。

推荐答案

这就像 Twitter的问题和我解决它在肮脏的方式

这篇关于的Andr​​oid 2.2 / 2.3不从的WebView上的YouTube应用加载YouTube视频的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆