Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7128665
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T11:09:44+00:00 2026-05-28T11:09:44+00:00

I have an audio recorder class in my application. It worked fine previously and

  • 0

I have an audio recorder class in my application. It worked fine previously and works fine on my HTC Desire but now doesn’t work on my LG. It’s no longer saving the audio file to the required path. I’m thinking it’s some setting on the phone that’s tripping it up, but I’m probably wrong.

An error occurs when writeAudioDataFile instantiates the FileOutputStream with filename in the try-catch block

private String getTempFilename(){
            String filepath = Environment.getExternalStorageDirectory().getPath();
            File file = new File(filepath,AUDIO_RECORDER_FOLDER);

            if(!file.exists()){
                    file.mkdirs();
            }

            File tempFile = new File(filepath,AUDIO_RECORDER_TEMP_FILE);

            if(tempFile.exists()){
                    tempFile.delete();
            }

            return (file.getAbsolutePath() + "/" + AUDIO_RECORDER_TEMP_FILE);
    }

private void writeAudioDataToFile(){
            byte data[] = new byte[bufferSize];
            String filename = getTempFilename();
            FileOutputStream os = null;

            try {
                    os = new FileOutputStream(filename);
            } catch (FileNotFoundException e) {
                    System.out.println("error");
                    e.printStackTrace();
            }

            int read = 0;

            if(null != os){
                    while(isRecording){

                            read = recorder.read(data, 0, bufferSize);

                            if(AudioRecord.ERROR_INVALID_OPERATION != read){
                                    try {                               
                                        os.write(data);

                                    } 
                                    catch (Exception e) {
                                            e.printStackTrace();
                                    }
                            }
                    }

                    try {
                            os.close();
                    } catch (IOException e) {
                            e.printStackTrace();
                    }
            }
    }

private void stopRecording(){
            if(null != recorder){
                    isRecording = false;

                    recorder.stop();
                    recorder.release();

                    recorder = null;
                    recordingThread = null;
            }

            copyWaveFile(getTempFilename(),getFilename());
            deleteTempFile();
    }

private void copyWaveFile(String inFilename,String outFilename){
            FileInputStream in = null;
            FileOutputStream out = null;
            long totalAudioLen = 0;
            long totalDataLen = totalAudioLen + 36;
            long longSampleRate = RECORDER_SAMPLERATE;
            int channels = 2;
            long byteRate = RECORDER_BPP * RECORDER_SAMPLERATE * channels/8;

            byte[] data = new byte[bufferSize];

            try {
                    in = new FileInputStream(inFilename);
                    out = new FileOutputStream(outFilename);
                    totalAudioLen = in.getChannel().size();
                    totalDataLen = totalAudioLen + 36;

                    //AppLog.logString("File size: " + totalDataLen);

                    WriteWaveFileHeader(out, totalAudioLen, totalDataLen,
                                    longSampleRate, channels, byteRate);

                    while(in.read(data) != -1){
                            out.write(data);
                    }

                    in.close();
                    out.close();
                    GlobalVar appState = ((GlobalVar)getApplicationContext());
                    appState.addAudioFile(outFilename);
            } catch (FileNotFoundException e) {
                    e.printStackTrace();
            } catch (IOException e) {
                    e.printStackTrace();
            }
    }

Error Log:

01-25 15:46:08.143: W/System.err(1828): java.io.FileNotFoundException: /mnt/sdcard/GeneralGUI2/Study1/Music/record_temp.raw (Permission denied)
01-25 15:46:08.143: W/System.err(1828):     at org.apache.harmony.luni.platform.OSFileSystem.openImpl(Native Method)
01-25 15:46:08.143: W/System.err(1828):     at org.apache.harmony.luni.platform.OSFileSystem.open(OSFileSystem.java:152)
01-25 15:46:08.143: W/System.err(1828):     at java.io.FileInputStream.<init>(FileInputStream.java:82)
01-25 15:46:08.143: W/System.err(1828):     at java.io.FileInputStream.<init>(FileInputStream.java:134)
01-25 15:46:08.143: W/System.err(1828):     at mfc.generalguixapi8.AudioActivity2.copyWaveFile(AudioActivity2.java:239)
01-25 15:46:08.143: W/System.err(1828):     at mfc.generalguixapi8.AudioActivity2.stopRecording(AudioActivity2.java:217)
01-25 15:46:08.143: W/System.err(1828):     at mfc.generalguixapi8.AudioActivity2.access$1(AudioActivity2.java:206)
01-25 15:46:08.153: W/System.err(1828):     at mfc.generalguixapi8.AudioActivity2$2.onClick(AudioActivity2.java:126)
01-25 15:46:08.153: W/System.err(1828):     at android.view.View.performClick(View.java:2408)
01-25 15:46:08.153: W/System.err(1828):     at android.view.View$PerformClick.run(View.java:8816)
01-25 15:46:08.153: W/System.err(1828):     at android.os.Handler.handleCallback(Handler.java:587)
01-25 15:46:08.153: W/System.err(1828):     at android.os.Handler.dispatchMessage(Handler.java:92)
01-25 15:46:08.153: W/System.err(1828):     at android.os.Looper.loop(Looper.java:123)
01-25 15:46:08.153: W/System.err(1828):     at android.app.ActivityThread.main(ActivityThread.java:4627)
01-25 15:46:08.153: W/System.err(1828):     at java.lang.reflect.Method.invokeNative(Native Method)
01-25 15:46:08.153: W/System.err(1828):     at java.lang.reflect.Method.invoke(Method.java:521)
01-25 15:46:08.153: W/System.err(1828):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:860)
01-25 15:46:08.153: W/System.err(1828):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:618)
01-25 15:46:08.153: W/System.err(1828):     at dalvik.system.NativeStart.main(Native Method)
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T11:09:44+00:00Added an answer on May 28, 2026 at 11:09 am

    For the newer versions, you need an explicit WRITE_EXTERNAL_STORAGE permission.

    Also, you are not allowed to write to the root of the external storage device. So, try creating a folder, and then write into that folder.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

A voice recorder doesn't need uncompressed Linear PCM audio. Compressed AMR would do fine.
I'm trying to develop an Audio Capture application using the AudioRecord class from android
I have recorded audio to a CaptureBuffer, but I can't figure out how to
I have an audio recording application for Windows Phone. It consists of a pivot
I have an app that lets user record their own audio. By now I'm
I have to following code to launch and the audio recorder on Android: final
I have an audio track with an image slideshow - e.g. there's image 1
I have an audio project I'm working on using BASS from Un4seen. This library
I have one audio file captured from my iphone. I want to upload this
I have G729 encoded audio files. I need to programmatically convert them to WAV

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.