Reputation: 19405
I have just started to develop my first Android app, and I am having a hard time figuring out how to start the microphone and have it listen, which is a main feature of my app.
I've searched the Android docs and I can't find much info on this.
Thanks in advance.
Upvotes: 7
Views: 29690
Reputation: 4981
You can use custom recorder:
final static int RQS_RECORDING = 1;
Uri savedUri;
Button buttonRecord;
@Override public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_test);
buttonRecord = (Button) findViewById(R.id.record);
buttonRecord.setOnClickListener(new Button.OnClickListener() {
@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
Intent intent = new Intent(
MediaStore.Audio.Media.RECORD_SOUND_ACTION);
startActivityForResult(intent, RQS_RECORDING);
}
});
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
// TODO Auto-generated method stub
if (requestCode == RQS_RECORDING) {
savedUri = data.getData();
Toast.makeText(MainActivity.this,
"Saved: " + savedUri.getPath(), Toast.LENGTH_LONG).show();
}
}
Upvotes: 0
Reputation: 28325
Maybe this can help (actually from the Android docs):
Audio Capture
android.media.MediaRecorder
.MediaRecorder.setAudioSource()
. You will probably want to use MediaRecorder.AudioSource.MIC
.MediaRecorder.setOutputFormat()
.MediaRecorder.setOutputFile()
.MediaRecorder.setAudioEncoder()
.MediaRecorder.prepare()
on the MediaRecorder
instance.MediaRecorder.start()
.MediaRecorder.stop()
.MediaRecorder
instance, call MediaRecorder.release()
on it. Calling MediaRecorder.release()
is always recommended to free the resource immediately.or:
Android Audio Recording Tutorial
Upvotes: 9