VOOZH about

URL: https://www.geeksforgeeks.org/android/how-to-create-google-lens-application-in-android/

⇱ How to Create Google Lens Application in Android? - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

How to Create Google Lens Application in Android?

Last Updated : 23 Jul, 2025

We have seen the new Google Lens application in which we can capture images of any product and from that image, we can get to see the search results of that product which we will display inside our application. 

What are we going to build in this article? 

We will be building a simple application in which we will be capturing an image from our device camera and after that, we will click on the Button to get the results for that product. A sample video is given below to get an idea about what we are going to do in this article. Note that we are going to implement this project using Java programming language. 

Steps to Implement Google Lens in Android

Step 1: Create a New Project

To create a new project in Android Studio please refer to How to Create/Start a New Project in Android Studio.

👁 lens-app-dir

Step 2: Adding dependency for language translation and View Binding

Navigate to the app > Gradle Scripts > build.gradle.kts file and add the following dependencies. We have added the dependencies for Firebase ML kit for image labelling, Volley for API Calls and Glide for image loading.

dependencies {
 ...
 implementation ("com.google.mlkit:image-labeling:17.0.9")
 implementation ("com.android.volley:volley:1.2.1")
 implementation ("com.github.bumptech.glide:glide:4.16.0")
}

Add View Binding support by adding the following code anywhere under the android{} scope

buildFeatures {
 viewBinding = true
}


Step 3: Adding permissions to access the Internet in your Android Apps AndroidManifest file

Navigate to the app > AndroidManifest.xml file and add the below code to it.

<uses-feature
 android:name="android.hardware.camera"
 android:required="true" />
<uses-permission android:name="android.permission.INTERNET" />


Step 4: Working with activity_main.xml file

Navigate to the app > res > layout > activity_main.xml and add the below code to that file. Below is the code for the activity_main.xml file. 

activity_main.xml:


Design UI:

👁 lens-app-design-ui


Step 5: Creating a model class for storing our data

Navigate to the app > java > {package-name}, Right-click on it, New > Java/Kotlin class and name your class as DataModel and add the below code to it. Comments are added inside the code to understand the code in more detail.

DataModel File:


Step 6: Creating a layout file for displaying our RecyclerView items

Navigate to the app > res > layout, Right-click on it, New > Layout Resource File and name it as search_result_rv_item and add the below code to it.

search_result_rv_item:


Step 7: Creating an adapter class for our RecyclerView

Navigate to the app > java > your app's package name > Right-click on it > New > Java class and name it as Adapter and add the below code to it.

Adapter File:


Step 8: Generating your API key

Go to the site https://serpapi.com/search-api and create your account with your Google account. This is a similar process as you signup on GeeksforGeeks. While generating your API key make sure to select the free trial option and proceed further. After going to the site shown above you will get to see the below screen. Simply sign in with your credentials and proceed further.

👁 Image

After proceeding further you have to simply Navigate to the My Account > Dashboard option to open the below screen. On this screen, you will get to see your API key.

👁 apiss


Step 9: Working with theMainActivity file

Go to the MainActivity file and refer to the following code. Below is the code for the MainActivity file. Comments are added inside the code to understand the code in more detail.

Now run your app and see the output of the app. Make sure to change your API key before running the app. 
Note: The search results might not be accurate upto an extent.

Note :To access the full android application this repository:Google Lens Application in Android

Output:


Comment

Explore