How to launch Youtube application to open a channel?

空扰寡人 提交于 2020-01-01 02:50:10

问题


I want to access from my application to youtube to open a channel. I've searched for a solution but i just found how to open/stream a video :

Intent i = new Intent(Intent.ACTION_VIEW, Uri.parse("vnd.youtube:VIDEO_ID"));
startActivity(i);

But what about opening directly a channel?

Thank you very much.


回答1:


Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse(urlStr));
startActivity(intent);

if you use the url of a youtube channel such as: http://www.youtube.com/user/JustinBieberVEVO

this should give you the option to open youtube to the given channel.

hope this helps!




回答2:


I know this answer is late and such but i wanted to share this anyway. This worked for me:

vnd.youtube://user/channel/channel_id

This opens the channel directly in the youtube app. Without asking the user.

Update

Didn't include any code because i was using React Native, and maybe people is looking for native code. Anyway here you go:

Linking
    .openURL( 'vnd.youtube://user/channel/' + channel_id )
    .catch( ... )

But, i think in native code it should be something like this:

Intent appIntent = new Intent(Intent.ACTION_VIEW, Uri.parse("vnd.youtube://user/channel/" + channel_id));
try {
  context.startActivity(appIntent);
} catch (ActivityNotFoundException ex) { ... }

I'm not too familiarized with native code so it may be wrong, but should work like a guide.



来源:https://stackoverflow.com/questions/9439995/how-to-launch-youtube-application-to-open-a-channel

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