Android Webview链接到m.youtube.com而不是youtube应用程序
我有我的应用程序,可以打开一个网页,上面有youtube视频的链接 我有两个问题:Android Webview链接到m.youtube.com而不是youtube应用程序,android,eclipse,video,youtube,playing,Android,Eclipse,Video,Youtube,Playing,我有我的应用程序,可以打开一个网页,上面有youtube视频的链接 我有两个问题: 链接可以打开m.youtube.com,但视频无法播放。只是用橙色突出显示,然后什么也没发生 没有在youtube应用程序中加载的选项 有什么想法吗?我在galaxy S2上测试,而不是在模拟器上测试,因为我知道emu不会有flash或youtube应用程序 非常感谢您的帮助,您将成为一名救生员 这是我的密码: package com.mytest; import android.app.Activi
package com.mytest;
import android.app.Activity;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.Window;
import android.webkit.WebChromeClient;
import android.webkit.WebView;
import android.webkit.WebViewClient;
public class mytestActivity extends Activity
{
final Activity activity = this;
private WebView webview;
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
// Check if the key event was the BACK key and if there's history
if ((keyCode == KeyEvent.KEYCODE_BACK) && webview.canGoBack()) {
webview.goBack();
return true;
}
// If it wasn't the BACK key or there's no web page history, bubble up to the default
// system behavior (probably exit the activity)
return super.onKeyDown(keyCode, event);
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
this.getWindow().requestFeature(Window.FEATURE_PROGRESS);
setContentView(R.layout.main);
// Don't create another webview reference here,
// just use the one you declared at class level.
webview = (WebView) findViewById(R.id.webview);
webview.getSettings().setJavaScriptEnabled(true);
webview.getSettings().setPluginsEnabled(true);
webview.setWebChromeClient(new WebChromeClient() {
public void onProgressChanged(WebView view, int progress)
{
activity.setTitle("Loading...");
activity.setProgress(progress * 100);
if(progress == 100)
activity.setTitle(R.string.app_name);
}
});
webview.setWebViewClient(new WebViewClient() {
@Override
public void onReceivedError(WebView view, int errorCode, String description, String failingUrl)
{
// Handle the error
}
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url)
{
view.loadUrl(url);
return true;
}
});
webview.loadUrl("http://mytesturl");
}
我的WebViewClient中有此应用程序,它会打开youtube视频本机应用程序:
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
if (url.contains("youtube.com")){
int indexStart = url.indexOf("?v=")+3;
int indexEnd = url.indexOf("&", indexStart);
if(indexEnd<indexStart)
return false;
String videoId = url.substring(indexStart,indexEnd);
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse("vnd.youtube://"+videoId)));
return true;
}
else
{
return false;
}
}
@覆盖
公共布尔值shouldOverrideUrlLoading(WebView视图,字符串url){
如果(url.contains(“youtube.com”)){
int indexStart=url.indexOf(“?v=”)+3;
int indexEnd=url.indexOf(“&”,indexStart);
if(indexEnd)