Open Youtube Channel calling YouTube App (Android)

本小妞迷上赌 提交于 2019-11-30 21:08:21

问题


I want to open YouTube App showing an specific channel, but this only execute the browser.

try 
        {
            Intent intent = new Intent(Intent.ACTION_VIEW);
            intent.setData(Uri.parse("http://www.youtube.com/"+channel));
            startActivity(intent);
        }
        catch (Exception e) 
        {
            startActivity(new Intent(Intent.ACTION_VIEW,Uri.parse("http://www.youtube.com/"+channel)));         
        }

I want to show this:


回答1:


Do research on library called YouTubeAndroidPlayerApi. This piece of code does exactly what you want.

Intent intent = YouTubeIntents.createUserIntent(this, channelName);
startActivity(intent);



回答2:


Use this code it will open the channel

 startActivity(new Intent(Intent.ACTION_VIEW,   Uri.parse("http://www.youtube.com/channel/UCw7FqRl9XzrlB_D1vOg_Gyg")));



回答3:


Simply you can't. The image you linked, is about the YouTube application, not the website.

EDIT: Take a look here: Launch an application from another application on Android




回答4:


Or, you could avoid the implementation of YouTubeAndroidPlayerApi Library: (kotlin)

const val URL_YOUTUBE = "https://www.youtube.com/channel/id"
const val URL_YOUTUBE_INAPP = "vnd.youtube.com/channel/id"

try{  
    //here we try to open the link in app
    startActivity(Intent(Intent.ACTION_VIEW, Uri.parse(URL_YOUTUBE_INAPP)))
}catch (e: Exception) {
   //the app isn't available: we open in browser`
   startActivity(Intent(Intent.ACTION_VIEW, Uri.parse(URL_YOUTUBE)))
}


来源:https://stackoverflow.com/questions/16510860/open-youtube-channel-calling-youtube-app-android

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!