如何在youtube应用程序或android studio的外部浏览器中打开单个tabhost选项卡?
我在android studio中使用tabhost,我所有的选项卡都是这样写的如何在youtube应用程序或android studio的外部浏览器中打开单个tabhost选项卡?,android,android-studio,browser,youtube,android-tabhost,Android,Android Studio,Browser,Youtube,Android Tabhost,我在android studio中使用tabhost,我所有的选项卡都是这样写的 /************* TAB4 ************/ intent = new Intent().setClass(this, Tour.class); spec = tabHost.newTabSpec("Tab8").setIndicator("TOUR") .setContent(intent); tabHost
/************* TAB4 ************/
intent = new Intent().setClass(this, Tour.class);
spec = tabHost.newTabSpec("Tab8").setIndicator("TOUR")
.setContent(intent);
tabHost.addTab(spec);
/************* TAB5 ************/
intent = new Intent().setClass(this, Blog.class);
spec = tabHost.newTabSpec("Tab9").setIndicator("BLOG")
.setContent(intent);
tabHost.addTab(spec);
等等
现在,我希望在youtube应用程序(如果已安装)中打开一个特定选项卡,或者在默认浏览器中打开一个特定选项卡(如果android设备上未安装youtube)
我找到了一些使用intent打开web浏览器的代码,但我不知道如何在我的代码中实现它或添加/调用youtube应用程序功能
以下是在浏览器中打开链接的意图
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse("http://www.stackoverflow.com"));
startActivity(intent);
我的第一个问题是如何在选项卡中实现此浏览器代码?
因为我想至少我可以在浏览器中打开链接(这更重要,因为我可以在多个链接上使用它)
我的第二个问题是,在尝试调用浏览器之前,如何实现调用youtube应用程序?因此,如果未安装youtube,该选项卡将首先尝试在youtube中打开链接,然后在浏览器中打开链接
基本上。。。
如何将这两个代码混合在一起
intent = new Intent().setClass(this, Blog.class);
spec = tabHost.newTabSpec("Tab9").setIndicator("BLOG")
.setContent(intent);
tabHost.addTab(spec);
及
会使
?????
结果是,如果你安装了youtube,通过添加链接,它可以在youtube上打开选项
这是我目前使用的代码
intent = new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse("http://www.youtube.com/playlist?list=PL4rWuj3mdfAtHqyufMu57C9LK8By9M_sy"));
String title = getResources().getString(R.string.chooser_title);
Intent chooser = Intent.createChooser(intent, title);
spec = tabHost.newTabSpec("Tab3").setIndicator("VIDEOS")
.setContent(chooser);
tabHost.addTab(spec);
intent = new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse("http://www.youtube.com/playlist?list=PL4rWuj3mdfAtHqyufMu57C9LK8By9M_sy"));
String title = getResources().getString(R.string.chooser_title);
Intent chooser = Intent.createChooser(intent, title);
spec = tabHost.newTabSpec("Tab3").setIndicator("VIDEOS")
.setContent(chooser);
tabHost.addTab(spec);