You can start two separate searches with your query as follows:
Youtube Search
Intent intent = new Intent(Intent.ACTION_SEARCH);
intent.setPackage("com.google.android.youtube");
intent.putExtra(SearchManager.QUERY, "Sunday Bloody Sunday");
intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
startActivity(intent);
Browser Search
Intent intent = new Intent(Intent.ACTION_WEB_SEARCH);
intent.putExtra(SearchManager.QUERY, "Sunday Bloody Sunday");
startActivity(intent);
Note that if the song is well known, one of the first results of the browser search will be the Youtube video.
Edit
Here is auto to create a search query for both Youtube and browsers:
private void startSearchIntent(String query) {
List<Intent> browserIntents = new ArrayList<>();
// Find browser intents
List<ResolveInfo> resInfo = getPackageManager().queryIntentActivities(new Intent(Intent.ACTION_WEB_SEARCH), 0);
// Create a search intent for each browser that was found
for (ResolveInfo info : resInfo) {
Intent browserIntent = new Intent(Intent.ACTION_WEB_SEARCH);
browserIntent.putExtra(SearchManager.QUERY, query);
browserIntent.setPackage(info.activityInfo.packageName.toLowerCase());
browserIntents.add(browserIntent);
}
// Create Youtube Intent
Intent youtubeIntent = new Intent(Intent.ACTION_SEARCH);
youtubeIntent.setPackage("com.google.android.youtube");
youtubeIntent.putExtra(SearchManager.QUERY, query);
youtubeIntent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
Intent chooserIntent = Intent.createChooser(youtubeIntent, query);
chooserIntent.putExtra(Intent.EXTRA_INITIAL_INTENTS, browserIntents.toArray(new Parcelable[]{}));
startActivity(chooserIntent);
}
Then you just have to call the method:
startSearchIntent("Sunday Bloody Sunday");
Hope it helps.