YouTube search from your App – Android


Search YouTube and show the result in the YouTube app.

Today in this post I am going to show you how you can open YouTube app from your android app and show search result.
What we are going to do is, make a simple YouTube search app. There will be an EditText and a Button. Clicking on the button the YouTube app will open with the search term of the EditText.
So for this, the YouTube app needs to be installed on the phone. But what if the app is not installed. For this rare case, we will open the WebView with the search term. So let’s get started.

RecyclerView with CheckBoxes – Android

Toast message and positioning – Android

Working with SharedPreferences – Android

Create a new project and make an EditText field and one Button.


This is how our main activity layout file looks like  –

In this project, we need two activities. One MainActvity and the other one is for WebView.

First, we need to check whether the YouTube app is installed or not. For that, we will make a method called appInstalledOrNot. 

We can check if an app is installed or not, by its package name. Here the parameter URI will accept the package name. So the method will return true if it finds the app.

The package name of the YouTube app is –

Now when the user clicks the Search button, perform this action. Check for the app –

Here is the complete code –

This is how our class looks like –

Note: You can’t change the key in putExtra. The key should be “query”.

Here is a screenshot of the search result.


Now that our work for the YouTube app is completed, let’s make the YouTubeWeb class. In this class, we just need a WebView to show the YouTube page.

This is our YouTubeWeb XML file –

In the YouTubeWeb activity, we will get the search term from previous activity, which is the MainActivity. So what we need to do is concatenate the search term with the YouTube search URL.
The search URL looks like this –

Now what we need to do is add the search term at the end of the URL and open that URL in the WebView.

That’s all you need to do to perform a simple YouTube search. In the next tutorial, we will learn how to show the search result within our app. If you have any doubts or any suggestion, please don’t forget to comment below.

You May Also Like

Leave a Reply

Your email address will not be published. Required fields are marked *