1

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:

enter image description here

Ahmad
  • 58,947
  • 17
  • 107
  • 133
C4TInD
  • 13
  • 1
  • 3

6 Answers6

8

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

Intent intent = YouTubeIntents.createUserIntent(this, channelName);
startActivity(intent);
Chor Wai Chun
  • 3,048
  • 21
  • 34
  • 1
    It should be `YouTubeIntents.createChannelIntent(this, channelName);` for opening a youtube channel instead. – viper Jun 19 '17 at 11:35
7

Use this code it will open the channel

 startActivity(new Intent(Intent.ACTION_VIEW,   Uri.parse("http://www.youtube.com/channel/UCw7FqRl9XzrlB_D1vOg_Gyg")));
Pir Fahim Shah
  • 9,541
  • 1
  • 73
  • 71
1

Check out my code for opening YouTube specific Channel:

//ID initialization
ImageView youtube = findViewById(R.id.youtubeID);

youtube.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {

            String youtubeURL = "https://www.youtube.com/papelbd";
            Intent youtubeIntent=null;

            try {

                youtubeIntent=new Intent(Intent.ACTION_VIEW);
                youtubeIntent.setPackage("com.google.android.youtube");
                youtubeIntent.setData(Uri.parse(youtubeURL ));
                startActivity(youtubeIntent);

            } catch (ActivityNotFoundException e) {

                youtubeIntent= new Intent(Intent.ACTION_VIEW);
                youtubeIntent.setData(Uri.parse(youtubeURL ));
                startActivity(youtubeIntent);
            }
        }
    });
Papel
  • 291
  • 2
  • 6
0

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

Community
  • 1
  • 1
0

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)))
}
J L
  • 9
  • 1
0

Follow this gist link below, If you face any trouble, just text me here.

https://gist.github.com/oalpayli/a25dca8dba396042b365af5bcf620393

oalpayli
  • 213
  • 1
  • 2
  • 8
  • A link to a solution is welcome, but please ensure your answer is useful without it: [add context around the link](//meta.stackexchange.com/a/8259) so your fellow users will have some idea what it is and why it’s there, then quote the most relevant part of the page you're linking to in case the target page is unavailable. [Answers that are little more than a link may be deleted.](/help/deleted-answers) – Espresso Mar 16 '21 at 13:42