【问题标题】:search in another application在另一个应用程序中搜索
【发布时间】:2018-01-06 20:43:52
【问题描述】:

我想知道是否可以在我的应用程序上搜索 youtube 或其他应用程序。

String s=" hi ";

 Intent intent= new Intent(Intent.ACTION_VIEW, Uri.parse("https://www.youtube.com/results?search_query=" + s));
        startActivity(intent); 

我可以使用此代码搜索 youtube 网站,但我想在 youtube android 应用程序 (com.google.android.youtube) 中搜索。我将使用以下代码进行语音搜索。

if (resultCode == RESULT_OK && null != data) {  

                ArrayList<String> result = data.getStringArrayListExtra(RecognizerIntent.EXTRA_RESULTS);
                mVoiceInputTv.setText(result.get(0));
                String text =mVoiceInputTv.getText().toString();

                String filename = text;     // full file name
                String[] parts = filename.split("\\ "); // String array, each element is text between spaces
                String beforeFirstSpace = parts[0];    // Text before the first space

                if(beforeFirstSpace.equalsIgnoreCase("Youtube")) {   
                    Intent intent = new Intent(getPackageManager().getLaunchIntentForPackage("com.google.android.youtube"));
                   intent.setAction(Intent.ACTION_SEARCH);
                   intent.putExtra(SearchManager.QUERY,text);
                    startActivity(intent);

                   finish(); System.exit(0);
}

使用此代码,我打开了 youtube 应用程序,但无法在应用程序中搜索。

【问题讨论】:

  • 除了 youtube 还有什么?
  • 支持带有查询字符串的http URL 是相当不寻常的。仅仅因为 YouTube 提供此功能并不意味着任何其他应用程序都提供此功能。
  • 我只想在 youtube 应用程序而不是网站中搜索 Intent intent = new Intent(getPackageManager().getLaunchIntentForPackage("com.google.android.youtube"));意图.setAction(意图.ACTION_SEARCH); intent.putExtra(SearchManager.QUERY,s);但它不起作用
  • 其他应用的示例;脸书,铬,信使......

标签: android


【解决方案1】:

您不能轻易做到这一点,因为其他应用可能(并且很可能)提供不同于 youtube 的另一个 API。

例如:

youtube 搜索 API: https://www.youtube.com/results?search_query=facebook

facebook 搜索 API: http://www.facebook.com/search/web/direct_search.php?q=%gmail

gmail 搜索 API: 邮箱:http://mail.google.com/mail/?search=query&view=tl&start=0&init=1&fs=1&q=%youtube

您会看到不同的模式。因此,您需要根据每个应用程序提供的搜索 API 手动、一一实现。

【讨论】:

    猜你喜欢
    • 2016-08-24
    • 2011-08-11
    • 1970-01-01
    • 2018-03-24
    • 2012-05-20
    • 1970-01-01
    • 2012-03-13
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多