6 Steps to add Computer Vision Super Powers to your Kotlin Android App

pcbuck April 22, 2021 0 Comments



6 Steps to add Computer Vision Super Powers to your Kotlin Android App


One week ago I’ve read the article from Sara Robinson about how to addComputer Vision to an iOS app.It is a great article describing playing around a cool idea: develop aserverless application combining the Firebase API (Cloud Storage, CloudFunctions and Cloud Firestore) with a Cloud Service like Google Vision API,offering Machine Learning powered image recognition.I start to thinking about a cool application using these services, but I’m anAndroid developer. So I tried to apply the same functionalities to an Androidapp developed in Kotlin language.This app allows you to upload a picture to Firebase Cloud Storage. This willtrigger a Cloud Function sending the picture to Vision API and retrieving backthe info we need. These infos will be stored back in a Cloud Firestoredatabase. Our Android application will listen for modification of theFirestore database and will update a View respectively.Let’s see how to develop this serverless Computer Vision app in 6 steps:

2. Create the Android project


Create from Android Studio the project linked to our Firebase project. Thanksto the Firebase integration with Android Studio, this is super-easy.Firebase Cloud Storage settings in Android Studio

4. Create the Cloud Function


Now we need to write some server logic using Firebase Cloud Function. Let’ssay that any time we sent the image on the Cloud Storage, we want to send thisimage to the Vision API.Here the instructions to setup the Cloud function in your project. After theconfiguration we can use this code for index.jsIn this code we are listening for change in Storagefunction.storage.object.onChangeWhen a new image is uploaded we take its URI (gcsPath) and prepare with thisthe request we want to perform on Vision API.

Install Android Studio


Android Studio provides a complex integrated development environment (IDE)including an advanced code editor and a set of application templates. Inaddition, it contains tools for development, debugging, testing, andperformance evaluations, which enable a faster and easier applicationdevelopment process. You can test your apps with a large range of pre-configured emulators, or on your own mobile device, build production apps, andpublish them on the Google Play store.Android Studio is available for Windows, Linux, and MacOS. The newest OpenJDK(Java Development Kit) is bundled with Android Studio.To get up and running with Android Studio, first check the system requirementsto ensure that your system meets them. The installation is similar for allplatforms. Any differences are noted below.

Create the app project


1. Open Android Studio if it is not already opened. 2. In the main Welcome to Android Studio window, click Start a new Android Studio project. 3. In the Create New Projectwindow, chooseEmpty Activityfor thePhone or Tabletand clickNext: 4. In the Configure your projectsection, enterHello Worldfor theApplication Name, leave the other settings to their default state 1. Click FinishAndroid Studio creates a folder for your projects, and builds the project withGradle (this may take a few moments).Tip: See the Configure your build developer page for detailed information.You may also see a “Tip of the day” message with keyboard shortcuts and otheruseful tips. Click Close to close the message.If you completed all the previous steps correctly, you should see somethinglike this:

Use a virtual device (emulator)


For the Hello World app will use the Android Virtual Device (AVD) manager tocreate a virtual device (also known as an emulator) that simulates theconfiguration for a particular type of Android device, and use that virtualdevice to run the app. Note that the Android Emulator has additionalrequirements beyond the basic system requirements for Android Studio.Using the AVD Manager, you define the hardware characteristics of a device,its API level, storage, skin and other properties and save it as a virtualdevice. With virtual devices, you can test apps on different deviceconfigurations (such as tablets and phones) with different API levels, withouthaving to use physical devices.

Create an Android virtual device (AVD)


In order to run an emulator on your computer, you have to create aconfiguration that describes the virtual device. 1. In Android Studio, select Tools>AVD Managerand a Virtual Devices screen will appear. If you’ve already created virtualdevices, the screen will display them (as shown in the figure below);otherwise you will see a blank list. 2. Click the +Create Virtual Deviceand wait for theSelect Hardwarewindow to show up. This will display a list of pre-configured hardwaredevices. For each device, the table provides a column for its diagonal displaysize (Size), screen resolution in pixels (Resolution), and pixel density (Density). 3. Choose a device such as Nexus 5x or Pixel XL, and click Next. The System Image screen will show up. 4. Click the Recommendedtab, if it is not already selected, and choose which version of the Androidsystem to run on the virtual device (such asOreo). 5. After choosing a system image, click Next and the Android Virtual Device (AVD) window will appear. You can also change the name of the AVD. Check your configuration and click Finish.

Run the app on the virtual device


Now we will run the Hello World app 1. In Android Studio, choose Run>Run appor click the Run iconin the toolbar. 2. The Select Deployment Targetwindow, underAvailable Virtual Devices, select the virtual device, which you just created, and clickOKThe emulator starts and boots just like a physical device. Depending on thespeed of your computer, this may take a while. Your app will start building,and once the emulator is ready, Android Studio will upload the app to theemulator and run it.You should see the Hello World app as shown in the following figure.Tip: When testing on a virtual device, it is good practice to launch it at thevery beginning of your session and don’t close it until you are done testingyour app, so that the deployment doesn’t have to go through the device startupprocess again. To close the virtual device, click the X button at the top ofthe emulator, choose Quit from the menu, or press Control-Q in Windows orCommand-Q in macOS.

How to install Android Pie 9 on Android Studio on Windows 10


Before going to install the Android Pie 9 you need to download therequirements of it. without Android Studio you are not able to install AndroidPie 9 on Windows. Firstly download Android Studio After that, the installationprocess is easy just follow the steps of installation.Required Files: * Download Android Studio * Windows 7/8/10 (32-Bit or 64-Bit) * 3 GB RAM * 1 GB RAM for Emulator * 2 GB Disk free Space * 1.5 GB for Android SDK file * 1280 x 800 Screen resolutionRelated:Step 1. When you have successfully download Android Studio, so go to downloadand double click to run the setup. After that, setup is started. Therefore, onthe welcome screen click on Next to go on.Install Android StudioStep 2. In this step Choose Components, choose which features of AndroidStudio you want to install on your computer. I will Check the Android VirtualDevice and click Next.Choose the ComponentsStep 3. In here Configure the settings for Android Studio, select theinstallation location and click Next.Configuration settingsStep 4. In this step your installation will complete, the installation processwill take at least 2 minutes. After that, you will face another screen thatAndroid Studio has been installed on your computer. and if you want to StartAndroid Studio just mark that, and finally click Finish.Installation complete

Setup Android Studio


Installing Android studio too much easy but setting up the setup for AndroidStudio is a bit complicated. in this case, you are required of high and speedinternet connection. because it will go to download the requirements ofAndroid Studio due to that it needs High internet connection, at leastaccording to me it will download more than a 10GB file, And your Disk spacemust be 15 GB. After that, you can test many Android developers on the AndroidStudio.Step 5. After that, you successfully installed the Android Studio you need toOpen that just go to Menu and Right>Click and Run As Administrator. Therefore,the Android Studio will Launch on the Welcome Wizard, set up your developmentenvironment for Android Studio. Additionally, the wizard will help portexisting Android Apps into Android Studio or create a new Android Applicationproject, and click Next.Open Android StudioStep 6. In this step choose the type of setup, you want for Android Studio.Simply I recommend you to choose Standard, or if you don’t want you cancontinue with the Custom installation, finally click on Next.Select installation typeStep 7. In this step select your theme, I will select the Light theme, and youcan choose the Dark theme also, and click Next.Choose your themeStep 8. In this step Verify the Settings for Android Studio, If you want toreview or change any of your installations, click previous then if not clickFinish. On the Downloading components, be aware that you need a high-speedinternet connection. because your Android Studio will download the requiredcomponents for Android Studio.Verify Settings for Android Studio

Create a New project on Android Studio


Once you download the complete components for Android Studio. therefore, youwill be directed to the window of Android Studio. this step is only for thefirst that users are using Android Studio. After that, if you want to useAndroid Studio you can create a new project or you can import export thefiles.

Install Android Pie 9


Step 9. Once you are completely done with the downloading of the components,now it is time to create a new project for Android Pie 9. Or you can testAndroid Oreo, Android Nought, Android KitKat and any other version of Android,in this case, open the Android Studio As Administrator and while opened, andclick on Start a new Android Studio Project.Start a new ProjectStep 10. In this step Choose your Project Activity, it is optional you canchoose any of them. As I have select Navigation Drawer Activity for AndroidPie 9, and finally click on Next.Select an ActivityStep 11. In this step, you need to Configure your project for installingAndroid Pie 9 on Android Studio. Therefore, you need to choose the Name,Package Name, Save Location, Language, Minimum API level and click Finish.Configure your ProjectStep 12. Wait for some minutes for the component installer to install therequested components for Android Studio. After that, you will be notified Doneand click Finish.Component InstallerStep 13. In this step click on AVD Manager for downloading Android Pie 9 onAndroid Studio.AVD ManagerStep 14. When the Virtual Machine Device (VMD) is open, simply click CreateVirtual Device.Create a new Virtual DeviceStep 15. In this step select a Hardware for your Android, I recommend you toselect Nexus 5X. Remember that you will select the resolution for the Android,then click Next.Select the Hardware

Leave a Reply

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