Audio input to android smartphone through headphone jack?

user1988170 picture user1988170 · Sep 30, 2013 · Viewed 41.8k times · Source

I'm trying to pass audio into an android phone through the headphone jack from an external player. I am reasonably sure it can be done for two reasons:

1) The square card reader works by sending its information through the headphone jack, so it can handle information input. https://squareup.com/reader
2) In order to get the audio from the player to the phone, I will be using a normal aux-aux cable, similar to those used connecting a music player to speakers. The fact that the audio can be passed to the speakers through a simple two ring cable. I know usually the two rings are used only for output with a third ring for input, but it seems to me this would suggest they are capable of inputting without the third ring.

My problem is there doesn't seem to be any api to deal with input through the headphone jack, and no one seems to know how the square reader works, or deals with the input. It looks like AudioRecord, http://developer.android.com/reference/android/media/AudioRecord.html, could have some potential to work, but it seems to need the size to be specified ahead of time, which is not ideal.

So if anyone could help me with any information on AudioRecord and how it works, or an alternative way of dealing with the input, I'd appreciate it. Also if someone knows for sure if I am correct in thinking the two ring cable can deal with input, that would also help a lot. Thanks.

Answer

ramizmoh picture ramizmoh · Jun 25, 2014

SquareUp teardown by North Street Labs is a good point of reference to understand the design of the SquareUp reader. (Archived Link)

Audio Recording With a Smartphone will shed some light on the headphone rings and their configuration.

BrandonLW's GitHub source code provides the Android source code to record and decode the sound data.

HTH