Question

Simple question, is there any way to read bytes/data from the headphone jack of an android phone? I know HTC made an app that lets headphones act as an antenna and gets Radio that way, but do i have to use native C++ for that or what? What i want to do is attach a double throw switch to the headphone jack and i want my phone to detect if the switch is pressed or not. Any way to do this??? I can tell this won't be an easy feat, but i've probably been through far worse.

Edit: even if it was the USB jack, i wudnt mind that either. I just want to attach a switch to my phone and use a program to detect if it's on or off

Was it helpful?

Solution

As the headphone jack typically includes a contact for a microphone to support headsets you could use digital/analog/digital conversion to transmit data. (That is how hardware extensions utilizing the headset jack like Square probably work).

But for a switch like you describe I would either go Bluetooth (which can just act like a simple serial connection in code; but you would need some custom but not terribly complicated hardware for this) or try Arduino for Android, which is designed exactly for this use case and uses USB (but I don't have personal experience with it).

No need for C++ or native in any case, everything is available via Java APIs.

OTHER TIPS

You are not going to be able to send data through the headphone jack into devices. Using the headphones as an antenna is different. It's not actually transmitting data into the phone, it's using the wire as an extension to the internal antenna (attached to a receiver inside the phone which generates the "data")

You should be able to do with the USB for your device though, you should focus on the USB anytime you want to transmit data from outside the phone into it, though you could probably also do it with an IR broadcaster/ bluetooth broadcaster set up instead of a wired switch.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top