0

I use a intent for record a sound.

But I don't know how save this sound in sdcard. I create a folder "file.mkdirs();". How catch the record and save on new folder (and change name)?

If is posible need save record afer push "Save" button no inmediately after record. I think need a var "recorded", if his is 0 not is recorded and if is 1 yes.

Afer on save function check if the sound are recorded and save in folder.

public class ObjSuperior extends ActionBarActivity {


    int peticion = 1;
    Uri url1;
    int recorded = 0;

    private final String ruta_Sonidos = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES) + "/Gueopic/";

    private File file = new File(ruta_Sonidos);

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_obj_superior);

        //Si no existe crea la carpeta donde se guardaran las fotos

        file.mkdirs();
    }


    public void grabarSo(View v) {
        Intent intent = new Intent(MediaStore.Audio.Media.RECORD_SOUND_ACTION);
        startActivityForResult(intent, peticion);
    }

    public void save(){
    //check if file are recorded and save on folder
    }

    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        if (resultCode == RESULT_OK && requestCode == peticion) {
            url1 = data.getData();
        }
    }
Phyron
  • 613
  • 1
  • 9
  • 25
  • 1
    possible duplicate of [Writing a file to sdcard](http://stackoverflow.com/questions/2455102/writing-a-file-to-sdcard) – Sufiyan Ghori Jan 08 '15 at 19:04

1 Answers1

0

This works for me, maybe you can use this?:

public void recordAudio(String fileName) {
final MediaRecorder recorder = new MediaRecorder();
ContentValues values = new ContentValues(3);
values.put(MediaStore.MediaColumns.TITLE, fileName);
recorder.setAudioSource(MediaRecorder.AudioSource.MIC);
recorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4);
recorder.setAudioEncoder(MediaRecorder.AudioEncoder.DEFAULT);
recorder.setOutputFile("/sdcard/sound/" + fileName);
try {
  recorder.prepare();
} catch (Exception e){
    e.printStackTrace();
}

final ProgressDialog mProgressDialog = new ProgressDialog(MyActivity.this);
mProgressDialog.setTitle(R.string.lbl_recording);
mProgressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
mProgressDialog.setButton("Stop recording", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int whichButton) {
    mProgressDialog.dismiss();
    recorder.stop();
    recorder.release();
    }
});

mProgressDialog.setOnCancelListener(new DialogInterface.OnCancelListener(){
    public void onCancel(DialogInterface p1) {
        recorder.stop();
        recorder.release();
    }
});
recorder.start();
mProgressDialog.show();

}

  • Thanks for answer, but I need use a intent for open a basic android recorder, no create a recorder. My code record the sound, but only need on execute sve function save this sound. – Phyron Jan 08 '15 at 19:45