I have android G1 firmware 1.6, I am trying to record voice from the app with the follow code.
MediaRecorder recorder = new MediaRecorder(); recorder.setAudioSource(MediaRecorder.AudioSource.MIC); recorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP); recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB); recorder.setOutputFile(PATH_NAME); recorder.prepare(); recorder.start();
my manifest.xml has:
<uses-permission android:name="android.permission.RECORD_AUDIO" />
I got:
09-23 14:41:05.531: ERROR/AndroidRuntime(1718): Uncaught handler: thread main exiting due to uncaught exception 09-23 14:41:05.551: ERROR/AndroidRuntime(1718): java.lang.RuntimeException: setAudioSource failed. 09-23 14:41:05.551: ERROR/AndroidRuntime(1718): at android.media.MediaRecorder.setAudioSource(Native Method)
how do I record voice properly?
My suggestion might look stupid, but it worked for me :)
Try giving permission as a nested tag. I believe there is an xml parsing issue somewhere with android packaging library.
As a Cyanogenmod-User I had to
Settings
-->Apps
--> Select your app -->Permissions
--> Check all permissions (should be the ones requested by the manifest) (on the device)After that recoding worked for me.
Open "
AndroidManifest.xml
" ->add
try this code it helps you a lot and its understandable .....
IMPORTANT - during the last few hours I tried to figure out how to check if the MIC is caught by a different application or not. I noticed that if 2 application address to MediaRecorder at the same time a RuntimeException will be tossed and you won't be able to use the mic, unless you restart your device (!!) I don't know if it's the best solution but it worked for me. perhaps it will save some of you a few hours some day..
Change
to
Worked for me.