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?
Please request
Manifest.permission.RECORD_AUDIO
permission dynamically for Marshmallow and above version.I had this exact problem, this solved it for me:
On the device you use for debugging go to Settings -> Apps -> {your app}. Then make sure all the app's permissions (in this case Audio Recording and Writing External Storage) are permitted.
Apprarently when installing an app not via Google Play Store you don't get asked to grant permissions and on some phones this will result in your debugging app not getting some permissions granted.
Check this even if some permissions in the manifest file are getting recognised (such as internet access) because for me some worked and some got automatically blocked.
Hope this helps.
I know this is a very old question but in Android Marshmallow you have to go on "Settings > Apps > Your App > Permissions" and enble Microphone permission.
That looks correct. Make sure other other applications aren't already using the MIC. Perhaps give the phone a restart and try again.
If you are running on Android M, then you need to request permissions to record audio on first run. To accomplish this, ask the user if you can record audio when the application starts:
For API 23+ you need to request the read/write permissions even if they are already in your manifest.