Reputation: 243
I am trying to record audio in my app On a button press
Intent intent = new Intent(MediaStore.Audio.Media.RECORD_SOUND_ACTION);
startActivityForResult(intent, ACTIVITY_RECORD_SOUND);
But it is giving me error
android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.provider.MediaStore.RECORD_SOUND }
but when i install any sound recorder from play store this error is gone but after recording the audio it does not return anything . It stay on the recorder window .
also what i have to write to get that audio file and upload it to the server
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
}
Upvotes: 0
Views: 1815
Reputation: 8835
You can use below code.
MediaRecorder recorder = new MediaRecorder();
recorder.setAudioSource(MediaRecorder.AudioSource.MIC);
recorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4);
recorder.setOutputFile(path);
// recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AAC); for mp3 audio
recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
recorder.prepare();
recorder.start();
and path could be anything where file exists.for e.g.
path = Environment.getExternalStorageDirectory() + "/Android/data/" + context.getApplicationContext().getPackageName() + "/files/" + "myrecording.m4a";
Upvotes: 1
Reputation: 1006574
But it is giving me error
There is no requirement for an Android device to have an activity that responds to that Intent
action.
when i install any sound recorder from play store this error is gone but after recording the audio it does not return anything . It stay on the recorder window .
That app has a bug, apparently.
also what i have to write to get that audio file and upload it to the server
Quoting the documentation for RECORD_SOUND_ACTION
, the output is "An uri to the recorded sound stored in the Media Library if the recording was successful". IOW, call getData()
on the Intent
delivered to onActivityResult()
, and that is supposed to be a Uri
pointing to the recorded audio. Note that this does not have to represent a file on the filesystem, let alone one that you can access.
Upvotes: 1