How to open Youtube video link in android app?(如何在Android应用中打开YouTube视频链接?)
本文介绍了如何在Android应用中打开YouTube视频链接?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的问题与其他有关如何打开YouTube链接的问题不同。我的问题是如何打开YouTube链接,然后当它在应用程序中打开时,它应该关闭YouTube应用程序,然后再次调用我的MainActivity
,这将打开YouTube应用程序。不过,它应该从scrath打开YouTube应用程序,而不是只显示在后台运行的前一个YouTube活动。
MainAcitivy-->Second Activity-->YouTube-->ThirdActivity-->YouTube
但我希望重新从头开始加载YouTube应用程序。但目前,我正在访问之前打开的YouTube应用程序,该应用程序位于后台。
维护活动
Intent intent = new Intent(MainActivity.this,ThirdActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
finish();
辅助活动
startActivity(new Intent(Intent.ACTION_VIEW, Uri.parse(link)));
sleep(10000);
Intent intent=new Intent(getApplicationContext(),ThirdActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
finish();
第三个活动
sleep(5000);
Toast.makeText(getApplicationContext(),"third",Toast.LENGTH_SHORT).show();
Intent intent=new Intent(getApplicationContext(),SecondActivity.class);
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
finish();
我希望每次从头开始再次加载它,但它显示了暂停的状态。如果您不明白我的问题,请您自由发表意见,我会尽量详细说明。提前谢谢。
推荐答案
以下示例代码将在youtube应用程序中打开youtube链接(如果此链接可用),否则将在浏览器中打开它:
public static void watchYoutubeVideo(String id) {
Intent appIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("vnd.youtube:" + id));
Intent webIntent = new Intent(Intent.ACTION_VIEW,
Uri.parse("http://www.youtube.com/watch?v=" + id));
try {
startActivity(appIntent);
} catch (ActivityNotFoundException ex) {
startActivity(webIntent);
}
}
edit:回答您的第二个需求。每次使用此代码调用新的Intent
时。它将打开此视频的应用程序或浏览器,并且不会显示加载的前一个视频。
这篇关于如何在Android应用中打开YouTube视频链接?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
沃梦达教程
本文标题为:如何在Android应用中打开YouTube视频链接?


猜你喜欢
- Android viewpager检测滑动超出范围 2022-01-01
- Android - 拆分 Drawable 2022-01-01
- 使用自定义动画时在 iOS9 上忽略 edgesForExtendedLayout 2022-01-01
- 想使用ViewPager,无法识别android.support.*? 2022-01-01
- 如何检查发送到 Android 应用程序的 Firebase 消息的传递状态? 2022-01-01
- MalformedJsonException:在第1行第1列路径中使用JsonReader.setLenient(True)接受格式错误的JSON 2022-01-01
- Android - 我如何找出用户有多少未读电子邮件? 2022-01-01
- 在测试浓缩咖啡时,Android设备不会在屏幕上启动活动 2022-01-01
- 用 Swift 实现 UITextFieldDelegate 2022-01-01
- android 4中的android RadioButton问题 2022-01-01