0

i created a voice recorder in android studio, but i cant find the recorded file on my phone. normally am meant to attach it to an email that will be sent, but i cant find it on my phone for me to add it as an attachment.This is my code written below

   private String outputFile = null;

   private MediaRecorder mRecorder;

    protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_home);
    Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
    setSupportActionBar(toolbar);


    outputFile = Environment.getExternalStorageDirectory().getAbsolutePath() + "/recording.3gpp";
    }




     public void startRecording() throws Exception {



    if(mRecorder!=null){
        mRecorder.release();
    }

    File fileOut = new File(outputFile);

    if(fileOut!=null){
        fileOut.delete();
    }


    mRecorder = new MediaRecorder();
    mRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
    mRecorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
    mRecorder.setOutputFile(outputFile);
    mRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);


        mRecorder.prepare();

    mRecorder.start();
}





public void stopRecording() {

    if(mRecorder != null) {
        mRecorder.stop();
        mRecorder.release();
    }
}

public void record(){



    new CountDownTimer(10000, 10000) { // 5000 = 5 sec

        public void onTick(long millisUntilFinished) {
            try {
                startRecording();
            } catch (Exception e) {
                e.printStackTrace();
            }
            Toast.makeText(HomeActivity.this, R.string.record_audio, Toast.LENGTH_LONG).show();
        }

        public void onFinish() {
            stopRecording();
            mProgressDialog.dismiss();
            Toast.makeText(HomeActivity.this, R.string.record_saved, Toast.LENGTH_LONG).show();
        }
    }.start();


}
STF
  • 1,485
  • 3
  • 19
  • 36
Henry
  • 91
  • 2
  • 12
  • have you added permissions? – Opiatefuchs Jun 21 '16 at 11:51
  • I have, added for recording and external storage – Henry Jun 21 '16 at 12:02
  • If You develop in API23 and above, you have to request permissions at runtime. Also if your App is lower than API23 but runs on a device with API23 and above, you need to adjust your app and request that permissions because it´s possible that these permissions are not added automatically. – Opiatefuchs Jun 21 '16 at 12:05
  • Am presently running it on 22 for test – Henry Jun 21 '16 at 13:29
  • Two things: first, you are deleting a file that is not null? I guess you want to delete the file if it has been created before? So `if(fileOut.exists())` must be called instead of `if(fileOut!=null)` . Second: why you set this in a countdown timer? And where are you starting the timer? You are nowhere calling `record()` or `startRecording()` methods..... – Opiatefuchs Jun 21 '16 at 13:58
  • I want it to record for only 10 seconds automatically, am using countdown timer to make it record for 10 seconds and stop recording after 10 seconds, am calling record from onclick of a button – Henry Jun 21 '16 at 14:02
  • I think there must be any problem and a error is thrown. From the code I can´t see anything missing. Make a log and check your logcat output.... – Opiatefuchs Jun 22 '16 at 05:39
  • Another possible issue is that your storage is not mounted. Be sure your storage is mounted with `Environment.getExternalStorageState().equals(android.os.Environment.MEDIA_MOUNTED);` – Opiatefuchs Jun 22 '16 at 05:44
  • Also, I am not sure if equal startTime and interval are working correct. It´s a behaviour of the countdowntimer that onTick is never called, if the remaining time is lower than the interval. Please do the following test and set the startTime to `20000` and interval to `10000` like new `CountDwonTimer(20000,10000)` – Opiatefuchs Jun 22 '16 at 05:52
  • Mounting it worked for me, thanks a lot – Henry Jun 22 '16 at 21:23
  • great, I put it as answer.. – Opiatefuchs Jun 23 '16 at 05:41

2 Answers2

0

It´s possible that your storage is not mounted. I faced especially on CyanogenMod systems that the sotrages are not mounted by default. Just be sure the storage is mounted by simply calling:

    boolean isMountend = Environment.getExternalStorageState().
equals(android.os.Environment.MEDIA_MOUNT‌​ED); 
Opiatefuchs
  • 9,800
  • 2
  • 36
  • 49
0

They won't show up when you connect via cable to copy them over. You need to be connected via WiFi go in an open the recording on your phone then up top right tap on the options. There will be an option to upload it to Google Drive. Once it is uploaded to your account, download it to your desktop drive.

Stephen Rauch
  • 47,830
  • 31
  • 106
  • 135