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 3 of 83: Naive Bayes?

Did Thomas Bayes ever think a small part to proving God's existence would be used in machines to classify data? I don't know, and most of us don't care. I'm waiting to use this and other algorithms in production to something I can showcase. Progress I am almost done with the second lesson of Udacity's introduction to machine learning course. The lesson, titled "Naive Bayes" reveals exactly the topic of discussion. Continuing with my goal, I've taken detailed notes about an example relating to the probability of having cancer based on a test. Because of my excitement, I've created a Python virtual environment for machine learning-related packages including TensorFlow, Scikit-learn, and numpy. I've already played around with inputting different values into a Bayes classifier. In terms of scheduling, today was actually a bland day with only four events (besides this) scheduled. Tomorrow has eight activities to occupy my day including l

Summer Break 2017, Day 6: Internet Presence

Over the course of 15 hours, I've become very conscious of my presence on the internet, and it all began with my father unintentionally showing the reach of various actions I've taken around the web. He originally tried to show me some records of his grandfather, but he eventually showed me Google image search results of himself, and I, of course, ended up appearing in the results since my name is literally a superset of his. I soon realized that comments I've made on YouTube videos have been indexed by Google. Internet privacy is a one-way street: you can park on the side, or you can keep driving down, but going the other direction requires immense amounts of work. The farther up the street you travel, the farther you've lost your privacy. Going up the street will let you access a greater amount of destinations, but the moment you wish to hide yourself from the people you don't want to find you, you can't just switch the gear into reverse and drive up the str

Summer Break 2017, Day 4 of 83: Short notes

What did I accomplish today? I finished my lesson on naive Bayes, learned about linear dependence, and began learning about graph-based algorithms. Because of my unfortunate procrastination and a request from a family member to do some unexpected work, don't have too much time today to document my experiences. I'll likely produce a follow-up or two on Saturday to compensate. Other news Today, the third developer preview for Android O came out. I've been reluctant to join the Android Beta Program, though. My Nexus 6P already dies around 40%, and I don't want to tempt the gods of battery life to increase that number. Sure, Android Nougat already introduced improvements to Doze, and Android O will put background execution limits for services, but I know the real problem is likely the hardware. Because my phone is from Best Buy, and my benefactor didn't get extended warranty, I'm essentially screwed until I get a new phone. (Hopefully, that new phone is a Pixe