-->

的Android 2.2 / 2.3不从的WebView上的YouTube应用加载YouTube视频

2019-10-16 21:57发布

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

我正在开发由标签的应用。 其中一个标签加载YouTube上的的WebView内的移动版本。 到现在为止还挺好。

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

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

提前致谢。

Answer 1:

这就像Twitter的问题 ,我解决它在一个肮脏的方式 。



文章来源: Android 2.2/2.3 doesn't load YouTube videos on the YouTube app from a WebView