Record Audio project problems, open failed, EACCES (Permission denied)

Hello..
I tried to build this tutorial
https://developer.xamarin.com/recipes/android/media/audio/record_audio/

but when I build the project, this error appear ::
/sdcard/test.3gpp: open failed: EACCES (Permission denied)

Here the Android Manifest file:
<?xml version="1.0" encoding="utf-8"?> <manifest xmlns:android="http://schemas.android.com/apk/res/android" android:versionCode="1" android:versionName="1.0" android:installLocation="internalOnly"> <application></application> <uses-sdk android:targetSdkVersion="15" android:minSdkVersion="15" /> <uses-permission android:name="android.permission.RECORD_AUDIO" /> <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" /> </manifest>

How I can solve the problem

Thanks and My regards ..

Tagged:

Answers

  • GeraldVersluisGeraldVersluis NLUniversity ✭✭✭✭

    It looks like your trying to open a file (/sdcard/test.3gpp) so you should probably include read permissions too.

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

  • Thanks Mr. Gerald
    The tutorial contains only the RECORD_AUDIO permission,
    I tried your suggest but it not successful ...

  • GeraldVersluisGeraldVersluis NLUniversity ✭✭✭✭

    Mr. even, why thank you :wink:

    I see, maybe something changed between the API version the example is using and you are using.
    Could you please show some code? What line does the error occur?
    Are you running on a emulator or a physical device? Does the /sdcard path exist?

  • You are welcome ..
    Thanks for some hopes to solve the problem Hahaha ..

    my code is same the tutorial, I don't change any thing.
    I run it on the emulator ..
    I don't know if the path exist or no ..

  • GeraldVersluisGeraldVersluis NLUniversity ✭✭✭✭

    What happens if you try to replace the /sdcard/test.3gpp with just test.3gpp?
    Or even better; Path.Combine(Android.OS.Environment.ExternalStorageDirectory.Path, "test.3gpp");

  • the first ::
    open failed: EROFS (Read-only file system)

    the second ::
    open failed: EACCES (Permission denied)

    And I even tried this project, it run only the first build, then it failed
    https://developer.xamarin.com/samples/monodroid/Example_WorkingWithAudio/

  • this tutorial talk how to play mp3 file exist in recourses
    https://developer.xamarin.com/recipes/android/media/audio/play_audio/

    Can we record on it and then play it ?

  • YkshLeoYkshLeo USMember ✭✭✭✭

    @SamerAlshurafa,

    Are you working with API 23+ ?

    Then you must keep in mind about the Android new feature Runtime Permissions.

    The permissions you are using :

    • android.permission.RECORD_AUDIO
    • android.permission.WRITE_EXTERNAL_STORAGE

    are categorised to Dangerous Permissions.
    So you need to request the permission even if they are already in your manifest.

    if (Android.Support.V4.App.ActivityCompat.CheckSelfPermission (this, Android.Manifest.Permission.WriteExternalStorage == (int)Android.Content.PM.Permission.Granted)) {
        //
        // Permission is granted
        //
    } else {
        //
        // Permission is denied
        //
    }
    

    Refer :

  • Thanks Vaikesh Leo for this information

    I work with API 15

  • YkshLeoYkshLeo USMember ✭✭✭✭

    Are you working on an emulator ?

    Is there a /sdcard in it ?

  • YkshLeoYkshLeo USMember ✭✭✭✭
    edited January 2016

    I assume you have no problem with permissions.
    I think you want to check if you have an External Storage ( /sdcard ) mounted to your device.

    Try this :

    if (Environment.MediaMounted.Equals (Environment.ExternalStorageState)) {
        //
        // External Storage present
        //
    }
    


    You can also try something like this too,
    If there is no external storage, it basically uses the internal cache to store.

    Java.IO.File root = GetDirectory(ApplicationContext);
    
    try {
        Java.IO.File fileDir = new Java.IO.File(root.AbsolutePath+"/sample/");
        fileDir.Mkdirs();
    
        Java.IO.File file = new Java.IO.File(fileDir,"sample.txt");
        Java.IO.FileWriter fileWriter = new Java.IO.FileWriter(file);
        Java.IO.BufferedWriter bufferedWriter = new Java.IO.BufferedWriter(fileWriter);
        bufferedWriter.Write("Sample work.");
        bufferedWriter.Close();
    } 
    
    catch (System.Exception ex) {
        throw ex;
    }
    
    
    
    
    public Java.IO.File GetDirectory(Android.Content.Context context)
    {
        string DirectoryName = "";
        if (Android.OS.Environment.ExternalStorageState.Equals (
            Android.OS.Environment.MediaMounted))
            CacheDir = new Java.IO.File (Android.OS.Environment.ExternalStorageDirectory, DirectoryName);
        else
            CacheDir = context.CacheDir;
    
        return CacheDir;
    }
    
  • Yes, I work on an emulator but I don't know if the '/sdcard' file exist.

    When I run the app on my device, the Unfortunately app stopped.

    Here the project
    https://developer.xamarin.com/samples/monodroid/Example_WorkingWithAudio/

    Here my project - I edit previous project
    http://www.mediafire.com/download/a337not86ihta0p/RecordAudio.rar

    The first code :
    yes External Storage present

    The second code :
    is to create txt file, but I would record audio !!!

  • YkshLeoYkshLeo USMember ✭✭✭✭

    Try debugging in to a device other than an emulator.

    I just suggested a sample code. By using the code I suggested as a reference just create your audio file instead of txt file.

    Fist you should make sure the specific path exist or not, before creating your file and saving in to that path.

  • Finally, the project run without any problems ..
    check the Attach file :)
    Thanks for all :)

Sign In or Register to comment.