Hello everybody! It's good to be back.

Anyway, going to the problem detail. I am currently developing an Android app that resembles the standard Android sound recorder. I already have the sufficient methods from MediaRecorder and MediaPlayer. After stopping the sound recording, an AlertDialog will appear, showing the EditText textbox for the file name. Here is the code snippet for the AlertDialog:

protected void displayFileSavePrompt() {
    LayoutInflater saveFile = LayoutInflater.from(ECGActivity.this);
    View saveFilePrompt = saveFile.inflate(R.layout.dialog_savefile, null);
    AlertDialog.Builder adb = new AlertDialog.Builder(ECGActivity.this);

    adb.setView(saveFilePrompt);

    final EditText fileNameField = (EditText) saveFilePrompt.findViewById(R.id.fileNameField);

    adb.setCancelable(false)
    .setTitle("Save File")
    .setPositiveButton("Save", new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            if(fileNameField.toString() == null) {
                Toast.makeText(ECGActivity.this, "Please enter a filename.", Toast.LENGTH_SHORT).show();
            } else {
                Intent getFileNameFromUser = new Intent();
                getFileNameFromUser.putExtra(fileNameInput, fileNameField.getText().toString());
                setResult(Activity.RESULT_OK, getFileNameFromUser);
                finish();
            }
        }
    })
    .setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            dialog.cancel();
            Toast.makeText(ECGActivity.this, "You have canceled saving your file.", Toast.LENGTH_SHORT).show();
            fileName.delete();
        }
    });

    AlertDialog saveFileDialog = adb.create();

    saveFileDialog.show();
}

The problem is, when I run the app, the filename is set to null.3gpp, not <filename>.3gpp.

I also have the startRecording() method:

protected void startRecording() throws Exception {
    ditchMediaRecorder();

    File ecgFolder = new File(Environment.getExternalStorageDirectory(), "ECG-to-Go");

    if(!ecgFolder.exists()) ecgFolder.mkdir();

    File fileName = new File(ecgFolder, fileNameInput + ".3gpp");
    MediaRecorder recorder = new MediaRecorder();

    recorder.setAudioSource(MediaRecorder.AudioSource.MIC);
    recorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
    recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AAC);
    recorder.setOutputFile(fileName.toString());
    recorder.prepare();
    recorder.start();
}

By the way, all these methods happen in just one activity. Thank you in advance for your help!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.20 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.