【发布时间】:2016-02-13 15:35:25
【问题描述】:
我是 android 开发新手,需要帮助。我有两个问题是:
- 我不知道如何在我的主目录中创建两个子目录。我知道如何在目录 (
File directory = new File(Environment.getExternalStorageDirectory()+"Saling-Wika/Audio&Text Files");) 中创建子目录,但我想要的是我的主子目录中有两个子目录(音频文件和文本文件是 Saling-Wika 目录中不同的两个子目录是主目录)。 -
我不知道如何将我的数据保存到我创建的子目录中。 这是音频数据来自的记录模块的代码:
public class RecordModule extends Activity { Button SpeakBtn, StopBtn; private MediaRecorder myAudioRecorder; private String outputFile = null; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.recordmodule); SpeakBtn = (Button) findViewById(R.id.SpeakBtn); StopBtn = (Button) findViewById(R.id.StopBtn); StopBtn.setEnabled(false); SpeakBtn.setEnabled(true); SimpleDateFormat datetime = new SimpleDateFormat("ddMMyyyyhhmmss"); String format = datetime.format(new Date()); outputFile = Environment.getExternalStorageDirectory().getAbsolutePath() + "/" + format + ".3gp"; myAudioRecorder = new MediaRecorder(); myAudioRecorder.setAudioSource(MediaRecorder.AudioSource.MIC); myAudioRecorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP); myAudioRecorder.setAudioEncoder(MediaRecorder.OutputFormat.AMR_NB); myAudioRecorder.setOutputFile(outputFile); SpeakBtn.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { try { myAudioRecorder.prepare(); myAudioRecorder.start(); } catch (IllegalStateException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } SpeakBtn.setEnabled(false); StopBtn.setEnabled(true); Toast.makeText(getApplicationContext(), "Recording started", Toast.LENGTH_SHORT).show(); } }); StopBtn.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { myAudioRecorder.stop(); myAudioRecorder.release(); myAudioRecorder = null; StopBtn.setEnabled(false); SpeakBtn.setEnabled(true); Toast.makeText(getApplicationContext(), "Audio recorded successfully", Toast.LENGTH_SHORT).show(); } }); }
我希望将我的音频数据存储到 Audio Files 目录中,但我不知道如何才能做到这一点。请帮帮我。
【问题讨论】:
-
单独制作你的子目录。你的问题太奇怪了。如果您可以创建一个子目录,那么您可以创建另一个我认为的子目录。
-
我终于分别做了子目录,第一个问题解决了。第二个怎么样?你能帮我吗? @greenapps
-
好吧,看来您是命令 myAudioRecorder 来做的。真的吗?那你为什么不这么说?你也忘了告诉现在发生了什么。你在哪里给你的录音机指明正确的目录?
-
我很困惑,@greenapps。是的 myAudioRecorder 做到了。我在哪里向我的录音机指示正确的目录是什么意思?
标签: android audio directory saving-data