Reputation: 3137
I have a button that when i tap on it i want to invoke Youtube app and search for predefined string(the search string is constant, i mean that Youtube app will display automatically the results). I know that for searching a channel, we put
Intent intent = new Intent(Intent.ACTION_VIEW);
intent.setData(Uri.parse("http://www.youtube.com/user/channel"))
But what about searching for a specific video (constant string)? Thank you for your help.
Upvotes: 6
Views: 4437
Reputation: 21
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);
}
call this method and pass your string as argument searchYt("freecodecamp")
Upvotes: 1
Reputation: 132982
try this Intent For Search on Youtube :
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);
Upvotes: 26