简体   繁体   中英

How to capture magnetic swipe data using headphone jack on Android?

If someone wants to write a android application that interacts with a physical device, specifically a reader using mobiles audio jack (eg Like how Square Inc is doing ) how is this done? Is there a api's to interact with the reader and get the cards data?

When a company creates a reader (physical device) does it provide relevant apis?

Are the physical details abstracted from the application programmer?

I have found the AudioRecord class which can record magnetic stripe data from audio jack But I can't fiqure out how to capture the actual card swipe event and to extract the meaningful data from RAW DATA Can any one help me with this

Any input is highly welcome!

The way this usually works is by encoding the data signal sent out by the device, like the card reader, in such a way that is can be decoded on the other end. Sound is a wave, and different amplitudes correspond to different loudness, and different frequencies correspond to different pitches. Imagine you have a sine wave, that varies between a high and a low frequency that are sufficiently different from each other so as to be easily distinguishable. The device sending out binary data (0's and 1's) can translate this data into an audio signal that varies by frequency (an alternative is varying amplitude). The receiver, in this case the mobile device, decodes the signal back into 0's and 1's. This is called "Frequency-shift-keying" (check out more here: http://en.wikipedia.org/wiki/Frequency-shift_keying ).

The simplest way to implement this is to try and find an open library that already does it. The device sending the data will also need to contain some kind of microcontroller that can perform the initial modulation. If you come across any good libraries, let me know, because I'm currently looking.

To answer your question, companies do not generally provide APIs etc to perform this.

This may seem like a lot of extra work to convert a digital signal, into an audio signal, and back, and you're right. However, every mobile device has essentially the same headphone jack, whereas the USB port on an Android is drastically different from an iPhone's lighting connector, or the connector in previous iPhones. Sending wirelessly through a network or Bluetooth is also an option, but they have their disadvantages as well.

Now the mobile device must be using a special headphone jack that supports microphones, otherwise it cannot receive input, it can only output sound. Most smartphones can do this.

Radios work on this principle (FM = Frequency modulation, AM = amplitude modulation). Old dial up modems used FSK, which is why you heard those weird noises each time it connected.

Hope that helps!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM