2 years ago

#17488

test-img

Coder25

ERROR : onRequestPermissionsResult: prepare() failedjava.io.FileNotFoundException: /data/audio.3gp: open failed: EACCES (Permission denied)

I am developing a audio recorder app using Media recorder for android(java). Here, I have to set the path of the audio file using the SetOutputFile(). I did try a few codes to set the file output path but none worked, and I got the above mentioned error in logcat

Here is the code I used to set output file location:

String path;
 path = Environment.getDataDirectory().getAbsolutePath();
 path+="/audio.3gp";

Here is my code on the onclick where I used most of MediaRecorder's methods:

 public void onClick(View view) {
                if(getPackageManager().hasSystemFeature(PackageManager.FEATURE_MICROPHONE)) {
                    mediarec.setAudioSource(MediaRecorder.AudioSource.MIC);
                }else{
                    Toast.makeText(getApplicationContext(),"No Mic present",Toast.LENGTH_SHORT).show();
                }
                mediarec.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
                mediarec.setOutputFile(path);
                mediarec.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
                try {
                    mediarec.prepare();
                } catch (IOException e) {
                    Log.e(TAG, "onRequestPermissionsResult: prepare() failed" + e);
                }
                mediarec.start();
            }
        };
        start.setOnClickListener(myonclick);

Here are the set of permissions I asked in android manifest(and I also asked for the runtime permission in mainactivity):

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

Here is the error shown in logcat:

E/Main Activity: onRequestPermissionsResult: prepare() failedjava.io.FileNotFoundException: /data/audio.3gp: open failed: EACCES (Permission denied)
E/MediaRecorder: start called in an invalid state: 4
E/AndroidRuntime: FATAL EXCEPTION: main

Can someone guide me how to solve this error?

Thanks in advance.

android

runtime-error

filenotfoundexception

mediarecorder

0 Answers

Your Answer

Accepted video resources