【问题标题】:Search a specific string in Youtube application from my app从我的应用程序中搜索 Youtube 应用程序中的特定字符串
【发布时间】:2012-03-25 13:25:10
【问题描述】:

我有一个按钮,当我点击它时,我想调用 Youtube 应用程序并搜索预定义的字符串(搜索字符串是恒定的,我的意思是 Youtube 应用程序将自动显示结果)。 我知道为了搜索频道,我们把

Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse("http://www.youtube.com/user/channel"))

但是搜索特定视频(常量字符串)呢? 感谢您的帮助。

【问题讨论】:

    标签: android youtube


    【解决方案1】:

    在 Youtube 上试试这个 Intent 搜索:

     Intent intent = new Intent(Intent.ACTION_SEARCH);
     intent.setPackage("com.google.android.youtube");
     intent.putExtra("query", "Android");
     intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
     startActivity(intent);
    

    【讨论】:

    • 完美答案!这正是我想知道的;)!谢谢 :)。 3 分钟后接受:p.
    • 现在还在工作!从 2012 年开始真的很棒,简直不敢相信!
    【解决方案2】:
    public void searchYt(String searchQuery) {
        Intent searchIntent = new Intent(Intent.ACTION_SEARCH);
        searchIntent.setPackage("com.google.android.youtube");
        searchIntent.putExtra(SearchManager.QUERY, searchQuery);
        startActivity(searchIntent);
      }
    
    

    调用此方法并将您的字符串作为参数传递 searchYt("freecodecamp")

    【讨论】:

      猜你喜欢
      • 2012-02-03
      • 1970-01-01
      • 2011-01-06
      • 2014-02-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多