In my WebView I'm loading YouTube official website: http://m.youtube.com/index?desktop_uri=%2F&gl=US#/
I want the user to be able to choose a video and simply watch it. The WebView doesn't do it so I thought that maybe I should run an intent to youtube app. First, I had to export the videoID from the link.
I tried this code, but it doesn't match the link..:
public class BrowserClient extends WebViewClient {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
//Check if YouTube video link
Log.d("WBC", "loading link: " + url);
String youTubeLink = "http://m.youtube.com/index?desktop_uri=%2F&gl=US#/watch?xl=xl_blazer&v=";
if (url.startsWith(youTubeLink)){
Log.d("WBC", "This is a YouTube 开发者_如何转开发link: " + url);
view.getContext().startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(String.format("http://www.youtube.com/v/%s", url.substring(youTubeLink.length(),url.length())))));
return true;
}
return super.shouldOverrideUrlLoading(view, url);
}
}
Any help?
Please try this code, it works in mine apps perfectly.
String sPath = "urlGoesHere";
Intent i = new Intent(Intent.ACTION_VIEW);
i.setData(Uri.parse(sPath));
startActivity(i);
精彩评论