Published in


Extract text from image in Android using Firebase ML Kit

Firebase ML Kit is a mobile SDK for Android and iOS that enables developers to build apps using machine learning with ease. It has various capabilities including text recognition, image labelling, on-device translation among others. In this post, we are going to create a simple Android app that recognizes text from images we take with our camera. So let’s get started.

Firebase ML APIs

Create the project

First off, create a new Android project with an Empty Activity. We are going to use minimum SDK version 23 and our primary language will be Java.

Create new project

Create the layout

Next, we need to create the layout for our app. The layout looks as below:

Connect your app to Firebase

We need to connect our app to Firebase in order to use the APIs. Android Studio has a built-in Firebase tool for easy linking of your app to Firebase. Click on Tools->Firebase in your Android Studio top menu. On the sidebar that will pop up, navigate to Firebase ML and Connect to Firebase then add the dependencies required by clicking on Add Firebase ML to your app and accepting the changes.

Firebase Assistant in Android Studio

In your build.gradle(app) file, check for this dependency:

implementation ‘’

Also add this line of code to your AndroidManifest.xml file

<meta-data android:name=”” android:value=”ocr”/>


In our file we are first going to bind our layout elements which we had an id for each in our layout. Next, we should set a click listener to our button that will perform the necessary operations. The first is checking for the camera permission. Don’t forget to add the permission to your AndroidManifest:

<uses-permission android:name=”android.permission.CAMERA”/>

In the method onActivityResult(), we perform the main operations of our app after the permission is granted by the user. We create a FirebaseVisionImage object from our image/bitmap. We then need to display the recognized text from our image to the TextView in our layout.

This project is hosted on GitHub:

And the Kotlin version:




Developer Circle: Nairobi

Recommended from Medium

Java Multithreading, Concurrency, and Parallelism — Part 4

Berry Data Partnership with YieldShield

Deploying FastAPI Web Application in AWS

The Rising Remote Workforce


TeamCity and Octopus Deploy Integration

The Good, The Bad, and The Ugly of Being a QA (or Tester)

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Licio Lentimo

Licio Lentimo

I write content on Android and Web technologies. Currently focusing on Cybersecurity. Find me on

More from Medium

Resolving HAXM Issue in Android Studio for Windows

Integration of Text to Speech feature of Huawei ML Kit in Book Reading Android app (Kotlin)- Part 4

Android Generic TableView — Fully Customizable Library for Presenting Data

Handling Large Images for Infinite RecyclerView with Offline Capability