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

Good Morning

It's a bright new day in 2017, and I've finally decided to host some public record of my life to preserve what little scraps of me survive after my death (that is if my consciousness isn't uploaded to data center by then). Slight morbidity aside, my ambitions for world domination are intensifying daily as I sit in my chair, mumbling to myself about ideas only a few in a hundred mile radius would even care about or understand. Current State of Affairs Without exposing any bank account-vital security question information, I'll discuss the most easily recognizable parts of my life: I live in Converse, TX , a small town of around 20,000 whose only job is to contribute to the San Antonio Metropolitan Statistical Area; basically, my municipality exists to act as a statistic. I attend Samuel Clemens High School as a sophomore who can't engage in many if any extracurricular events because of the following reason. During evenings, I attend my father's (master...

Python is Cool. Python is Great.

I've immersed myself in programming with the easiest language to learn, and I'm currently trying to make my own command line utility for training the agents in The Companions Project . Sure, I may know jack squat about how to implement machine learning on the scale I wish to happen, but I do know one vital aspect of it: Python . Python compared to Java is the equivalent of Chinese checkers to chess . Chinese checkers is incredibly easy to learn but understandably difficult to master. Chess has a higher barrier to entry, but once you're over the wall, one can has some very complex possibilities to learn. While I now see programming in Python is incredibly simpler to begin, my Java-minded self took a quick look at the syntax and only bothered to look at code snippets to scare me into believing that Python is the language of the devil with forced indentation and syntax like this: class HelloWorld:     def hello(self, name=None):         if name is ...

What's a TSI Test?

I took the TSI test on Wednesday, but I wasn't the first one in the lab to finish. I blame my proctor's slowness at informing me on some prerequisites that Administration didn't inform me about and my own apathy to a test that didn't seem to put up much of a fight. Three other people beat me to the punch, but I still managed to finish before the end of third period. Since this test doesn't involve a non-disclosure agreement that people really don't care about anyway , I'll talk about the contents of the test. There's nothing too interesting about the test. I likely could have gotten a perfect score if I tried, and that's not just me being cocky. There was no advanced math on the test (nothing higher than algebra), but the reading sections are slightly more comprehensive than the STAAR test's. I literally mean slightly more comprehensive; the STAAR test is more fiction-oriented while the TSI's reading (I think) only consists of nonfiction pas...