【发布时间】: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 还有什么?
-
创建一个
Intent Chooser。 developer.android.com/training/basics/intents/… -
支持带有查询字符串的
httpURL 是相当不寻常的。仅仅因为 YouTube 提供此功能并不意味着任何其他应用程序都提供此功能。 -
我只想在 youtube 应用程序而不是网站中搜索 Intent intent = new Intent(getPackageManager().getLaunchIntentForPackage("com.google.android.youtube"));意图.setAction(意图.ACTION_SEARCH); intent.putExtra(SearchManager.QUERY,s);但它不起作用
-
其他应用的示例;脸书,铬,信使......
标签: android