【问题标题】:Open Youtube Channel calling YouTube App (Android)打开 Youtube 频道调用 YouTube 应用 (Android)
【发布时间】:2013-05-06 19:49:54
【问题描述】:

我想打开显示特定频道的 YouTube 应用,但这只会执行浏览器。

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)));         
        }

我想展示这个:

【问题讨论】:

    标签: android youtube channel youtube-channels


    【解决方案1】:

    使用此代码将打开通道

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

    【讨论】:

      【解决方案2】:

      对名为 YouTubeAndroidPlayerApi 的库进行研究。这段代码正是你想要的。

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

      【讨论】:

      • 它应该是 YouTubeIntents.createChannelIntent(this, channelName); 用于打开 youtube 频道。
      【解决方案3】:

      查看我打开 YouTube 特定频道的代码:

      //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);
                  }
              }
          });
      

      【讨论】:

        【解决方案4】:

        只是你不能。 您链接的图片是关于 YouTube 应用程序的,而不是网站。

        编辑:看看这里:Launch an application from another application on Android

        【讨论】:

        • 对不起,我可能拼错了...我想用X频道打开应用程序。
        【解决方案5】:

        或者,您可以避免实现 YouTubeAndroidPlayerApi 库:(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)))
        }
        

        【讨论】:

          【解决方案6】:

          按照下面的这个要点链接,如果您遇到任何问题,请在此处给我发短信。

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

          【讨论】:

          猜你喜欢
          • 2015-07-07
          • 2015-03-10
          • 1970-01-01
          • 2014-06-20
          • 2013-08-09
          • 2013-08-29
          • 2012-03-15
          • 2016-10-30
          • 2016-03-23
          相关资源
          最近更新 更多