tba*_*tba 12 youtube android android-intent
我有一个链接到YouTube视频的移动网站.在Android上,单击此链接会显示一个对话框,要求用户使用其浏览器或Youtube应用程序"完成操作".
有没有办法绕过这个屏幕,只是在Youtube应用程序中播放视频?(例如,使用youtube:// URL.)
谢谢!
Tim*_*Tim 19
这是你如何做到这一点:
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("vnd.youtube://" + id));
startActivity(intent);
Run Code Online (Sandbox Code Playgroud)
id是url中问号后面的标识符.例如:youtube.com/watch?v = ID
另一种方式是:
Intent videoIntent = new Intent(Intent.ACTION_VIEW);
videoIntent.setData(url);
videoIntent.setClassName("com.google.android.youtube", "com.google.android.youtube.WatchActivity");
startActivity(videoIntent);
Run Code Online (Sandbox Code Playgroud)
......
最好的方法
try {
Intent intent = new Intent(Intent.ACTION_VIEW, Uri.parse("vnd.youtube://" + id));
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
} catch (ActivityNotFoundException e) {
// youtube is not installed.Will be opened in other available apps
Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse("https://youtube.com/watch?v=" + id));
startActivity(i);
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
21863 次 |
| 最近记录: |