Skip to main content

Summer Break 2017, Day 5: How Hard is it to Upload a Photo to Firebase?

God help you if you ever decide to implement camera functionality in Android.

I didn't have much planned today, but thank goodness I didn't.

The Setup

Here's the dilemma: I wanted to make a very simple app that will let me take a photo of text and have it read out to me. Using the Google Cloud Vision API,  I can essentially scan documents and listen to their contents instead of having to use my eyes and scan the thing. It will be great for accessibility and so on, but the thing is I can't have the Cloud Vision API scan documents that I haven't taken. I want to do processing in the cloud to model common app architecture and to reduce strain on the client app.

Here's the service flow:
  1. Client app takes photo
  2. Client app uploads photo to Cloud Storage for Firebase
  3. Cloud Functions scans the document for text
  4. Cloud Functions updates Firebase Database with scanned text
  5. Client app intercepts database update
  6. Client app speaks text from database

The Conflict

Despite what I hinted at earlier, item one is very easy. A simple intent with action ACTION_IMAGE_CAPTURE will launch the default camera app (to my knowledge) to take the photo. However, hell breaks loose on item two as there's no clear way to get the URI of the taken image into the client API for Cloud Storage for Firebase. The library does have a StorageReference.putFile() method that accepts the URI, but I can't use that method since the intent data or extras don't return anything useful to me. 
Note: while I might be able to upload the Bitmap directly from memory using a ByteArrayOutputStream, I've actually had problems with large images crashing apps. Even if that wasn't a concern, I couldn't find out where the bitmap was supposed to be provided in the app intent.

After looking through post after post on StackOverflow, no solution sticks. I try the official Android documentation, but, even when actually reading the directions and following the code verbatim, I'm left with exception after exception. (Yes, I read the stack traces. They've ranged from NullPointerExceptions to FileUriExposedExceptions.)

Five hours in, I throw in the towel and check out this library that does what I need and more.
After hours of frustration, I think I know why some iOS developers that know Android pretty well say that developing for Android is hard. While I don't know how much better (or worse) doing this on iOS would be, I will say for something so commonplace in Android apps, I'm a bit disappointed in Google for not providing a more robust API to do something as simple as getting the location of an image.

Maybe my novice developer experience (if you can even call it that) is making me think that this is unnecessarily difficult when the average software developer does work an order of magnitude harder than this. Although, I think that's the imposter syndrome speaking.

TL;DR: Android's docs for getting the URI of an image do not function, and I ended up using a library that does what should really be in the framework or in the support libraries.

Frustration aside, I'm going to salvage some of my dignity by using a library to complete a project that literally could have taken six hours. Good night.

Comments

Popular posts from this blog

Summer Break 2017, Day 2 of 83: All Hail the Schedule

I think the plan's working; I'm already motivated to accomplish everything I've planned in The Schedule . Thanks to Google Calendar, I have the flexibility to change what I do on a daily basis. (I know, it's like I'm a spokesperson for Google right now, but you haven't seen half of it.) With Calendar's goals feature, I specify frequency and position of goals I want to accomplish, and machine learning ensures the times work out for me. Sure, it's a bit finicky right now, but at least I didn't have to make a hundred something event times for goals that don't have entirely consistent definite start and end time. MOOCs and More Because of my existing knowledge and experience with Udacity , I've decided to use their online courses to enrich my currently unstructured learning. Here's everything scheduled to be completed during the summer: Introduction to Machine Learning (the big one, the real thing I want to accomplish) Introd...

My First AP Test

In around 10–15 minutes, I will begin the AP Physics 1 exam. It's questionable whether I'll obtain a score of five, but I know I can easily obtain a four. Does MIT or Caltech or Stanford or whoever care if I obtain a five? Well, I know MIT doesn't even care if I take the test as they only accept credit for a five on the AP Physics C exam. As for the others, I probably should've done some research. That doesn't matter now. I just looked over my mock test with another highly intelligent student, and we both know we can easily obtain a four. I know how torque works; I know how movement in two dimensions works; heck, I even remember​ how to build a DC circuit. Kirchoff has nothing on me. I know that the junction rule states that a circuit's input current must equal it's output. I understand that resistors have the same current in a series but the same voltage in parallel. I am going to perform very well. (As long as I don't bomb the free-response quest...