我想知道可以在我的應用程序中搜索youtube或其他應用程序。在另一個應用程序中搜索
String s=" hi ";
Intent intent= new Intent(Intent.ACTION_VIEW, Uri.parse("https://www.youtube.com/results?search_query=" + s));
startActivity(intent);
我可以搜索使用的YouTube網站,這個代碼,但我想在Android版YouTube應用(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之外還有什麼? – Kharda
創建一個'Intent Chooser'。 https://developer.android.com/training/basics/intents/sending.html#AppChooser –
用查詢字符串支持'http' URL是非常不尋常的。僅僅因爲YouTube提供這個功能並不意味着其他任何應用都可以。 – CommonsWare