views:

257

answers:

1

Hello everybody,

I'm new in Android development and I have the next question/problem.

I'm playing around with the MediaRecorder class to record just audio from the microphone. I'm following the steps indicated in the official site: http://developer.android.com/reference/android/media/MediaRecorder.html

So I have a method that initializes and configure the MediaRecorder object in order to start recording. Here you have the code:


        //initializes audio recorder
        MediaRecorder mrecorder = new MediaRecorder();
        //configure the input sources
        mrecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
        //set the output format
        mrecorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
        //set the audio encoding
        mrecorder.setAudioEncoder(MediaRecorder.AudioEncoder.DEFAULT);
        //specify the output file
        mrecorder.setOutputFile("/sdcard/test.3gp");
        //prepare for recording
        try {
            mrecorder.prepare();
        } catch (IllegalStateException e) { 
            e.printStackTrace();
            Log.d("Syso". e.toString());
        } catch (IOException e) { 
            e.printStackTrace();
            Log.d("Syso". e.toString());
        }

When I execute this code in the simulator, thanks to logcat, I can see that the method prepare() gives an exception when is called:


java.io.FileNotFoundException: /sdcard/test.3gp (Permission denied)

And I have no idea why this is happening. Due to the message of the exception, I've given permissions in the manifest to access to storage by adding the following line to the xml:


<uses-permission android:name="android.permission.STORAGE" />

But this doesn't fix anything and I still get the same exception all the time. The SDCard is mounted according to the emulator, so I have no clue.

Can anyone give me some advise??

Thanks in advanced!!

+3  A: 

Add the WRITE_EXTERNAL_STORAGE permission to AndroidManifest.xml.

JRL
Thank you very much!!
arakn0