title: Android how to get popup when we click stop button in android and specify file name of audio
body: <p>I have 2 problem in my audio recording application</p>
  
  <p>1) I want a popup window which ask name of audio when i press stop button of audio recording activity, i have created this activity but it doesn't open popup and ask name, it stores audio with currentTimeMillis which i have specified in code, So how to get popup which ask to enter name of audio and it stores audio with particular entered name.</p>
  
  <p>2) I have set timer of 20 seconds, mediaRecoder.setMaxDuration(20000); So what i want is after 20 seconds of time, i want that recording stop automatically and popup comes and ask for recorded audio name, same as requirement 1 but it should stop automatically after 20 seconds.</p>
  
  <p>Below is my Activity Code.</p>
  
  <pre><code>public class Record_Audio extends Activity {
  
  private static final String AUDIO_RECORDER_FILE_EXT_3GP = ".3gp";
  private static final String AUDIO_RECORDER_FILE_EXT_MP4 = ".mp4";
  private static final String AUDIO_RECORDER_FOLDER = "AudioRecorder";
  
  private MediaRecorder recorder = null;
  private int currentFormat = 0;
  private int output_formats[] = { MediaRecorder.OutputFormat.MPEG_4,
          MediaRecorder.OutputFormat.THREE_GPP };
  private String file_exts[] = { AUDIO_RECORDER_FILE_EXT_MP4,
          AUDIO_RECORDER_FILE_EXT_3GP };
  Chronometer myChronometer;
  Handler seekHandler = new Handler();
  
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.record_audio);
  
      myChronometer = (Chronometer) findViewById(R.id.chronometer);
  
      setButtonHandlers();
      enableButtons(false);
      setFormatButtonCaption();
  }
  
  private void setButtonHandlers() {
      ((Button) findViewById(R.id.btnStart)).setOnClickListener(btnClick);
      ((Button) findViewById(R.id.btnStop)).setOnClickListener(btnClick);
      ((Button) findViewById(R.id.btnFormat)).setOnClickListener(btnClick);
      ((Button) findViewById(R.id.allrecording)).setOnClickListener(btnClick);
  }
  
  private void enableButton(int id, boolean isEnable) {
      ((Button) findViewById(id)).setEnabled(isEnable);
  }
  
  private void enableButtons(boolean isRecording) {
      enableButton(R.id.btnStart, !isRecording);
      enableButton(R.id.btnFormat, !isRecording);
      enableButton(R.id.btnStop, isRecording);
  }
  
  private void setFormatButtonCaption() {
      ((Button) findViewById(R.id.btnFormat))
              .setText(getString(R.string.audio_format) + " ("
                      + file_exts[currentFormat] + ")");
  }
  
  private String getFilename() {
      String filepath = Environment.getExternalStorageDirectory().getPath();
      File file = new File(filepath, AUDIO_RECORDER_FOLDER);
  
      if (!file.exists()) {
          file.mkdirs();
      }
      return (file.getAbsolutePath() + "/" + System.currentTimeMillis() + file_exts[currentFormat]);
  }
  
  
  private void startRecording() {
      recorder = new MediaRecorder();
      recorder.setAudioSource(MediaRecorder.AudioSource.MIC);
      recorder.setOutputFormat(output_formats[currentFormat]);
      recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
      recorder.setOutputFile(getFilename());
      recorder.setOnErrorListener(errorListener);
      recorder.setOnInfoListener(infoListener);
  
  
      try {
          recorder.prepare();
          recorder.start();
      } catch (IllegalStateException e) {
          e.printStackTrace();
      } catch (IOException e) {
          e.printStackTrace();
      }
      myChronometer.setBase(SystemClock.elapsedRealtime());
      myChronometer.start();
  }
  
  private void stopRecording() {
      if (null != recorder) {
          recorder.stop();
          recorder.reset();
          recorder.release();
  
          recorder = null;
          myChronometer.stop();
      }
  }
  
  private void displayFormatDialog() {
      AlertDialog.Builder builder = new AlertDialog.Builder(this);
      String formats[] = { "MPEG 4", "3GPP" };
  
      builder.setTitle(getString(R.string.choose_format_title))
              .setSingleChoiceItems(formats, currentFormat,
                      new DialogInterface.OnClickListener() {
  
                          @Override
                          public void onClick(DialogInterface dialog,
                                  int which) {
                              currentFormat = which;
                              setFormatButtonCaption();
  
                              dialog.dismiss();
                          }
                      }).show();
  }
  
  private MediaRecorder.OnErrorListener errorListener = new MediaRecorder.OnErrorListener() {
      @Override
      public void onError(MediaRecorder mr, int what, int extra) {
          Toast.makeText(Record_Audio.this, "Error: " + what + ", " + extra,
                  Toast.LENGTH_SHORT).show();
      }
  };
  
  private MediaRecorder.OnInfoListener infoListener = new MediaRecorder.OnInfoListener() {
      @Override
      public void onInfo(MediaRecorder mr, int what, int extra) {
          Toast.makeText(Record_Audio.this,
                  "Warning: " + what + ", " + extra, Toast.LENGTH_SHORT)
                  .show();
      }
  };
  
  private View.OnClickListener btnClick = new View.OnClickListener() {
      @Override
      public void onClick(View v) {
          switch (v.getId()) {
          case R.id.btnStart: {
              Toast.makeText(Record_Audio.this, "Start Recording",
                      Toast.LENGTH_SHORT).show();
              enableButtons(true);
              startRecording();
  
              break;
          }
          case R.id.btnStop: {
              Toast.makeText(Record_Audio.this, "Stop Recording",
                      Toast.LENGTH_SHORT).show();
              enableButtons(false);
              stopRecording();
  
              break;
          }
          case R.id.btnFormat: {
              displayFormatDialog();
  
              break;
          }
  
          case R.id.allrecording: {
              Intent intent = new Intent(Record_Audio.this, PlayAudio.class);
              startActivity(intent);
              break;
          }
          }
      }
  };
  }
  </code></pre>
  
  <p>So mainly this below function is responsible for all the operation but i am not getting how to code.</p>
  
  <pre><code>private String getFilename() {
  String filepath = Environment.getExternalStorageDirectory().getPath();
  File file = new File(filepath, AUDIO_RECORDER_FOLDER);
  
  if (!file.exists()) {
      file.mkdirs();
  }
  return (file.getAbsolutePath() + "/" + System.currentTimeMillis() + file_exts[currentFormat]);
  }
  </code></pre>
  
  <p>Any help would be appreciated. Thanks in advance... </p>