I am trying to get audio input through the headphone jack for my final year project. It would be a great help if someone can share some code on how to capture the data. I have been trying but as I am fairly new to android, I couldn't find any API for headphone jack in MediaRecorder.AudioSource... There are only these sources available: http://developer.android.com/reference/android/media/MediaRecorder.AudioSource.html
If you choose e.g.
MediaRecorder.AudioSource as the input then a TRRS plug attached to your phone will automatically be used as the input instead of the internal microphone.
But you have two keep three things in mind:
1) Number of channels
The TRRS plug has two lines for left and right channel of the headphone but only one line for the external microphone (see e.g. this description of the plug). So you can only do monophonic recordings (the only smartphone exception at the moment: the Sony Z2 has a new TRRRS plug). You can build an adapter on your own (see e.g. the pictures here).
You can't connect the line-out of e.g. a CD player directly to the input. You need to use e.g. a resistive voltage divider to reduce the output level to avoid overload.
3) Signal manipulation
Typically, there is smartphone-manufacturer-dependent fancy signal processing in the firmware like automatic gain control (AGC) and/or equalization, noise suppression, echo cancellation. You can't switch it off, so you don't get a perfect copy of your input signal.