[英]Android I want to access my external storage folder
How can I access my External storage folder? 如何访问我的外部存储文件夹?
I am trying to fetch the files from external storage and that want to be display in my application. 我正在尝试从外部存储中获取文件,并且希望在我的应用程序中显示它们。 How can i get an audio file from external storage and view it in my application? 如何从外部存储中获取音频文件并在应用程序中查看?
Here's my 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]);
}
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();
}
}
private void stopRecording() {
if (null != recorder) {
recorder.stop();
recorder.reset();
recorder.release();
recorder = null;
}
}
private View.OnClickListener btnClick = new View.OnClickListener() {
@Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.button1: {
Toast.makeText(call1.this, "Start Recording",
Toast.LENGTH_SHORT).show();
enableButtons(true);
startRecording();
break;
}
case R.id.button2: {
Toast.makeText(call1.this, "Stop Recording", Toast.LENGTH_SHORT)
.show();
enableButtons(false);
stopRecording();
break;
}
case R.id.button3: {
Toast.makeText(call1.this, "Playing Audio", Toast.LENGTH_SHORT)
.show();
}
Can you do this? 你能做这个吗?
File file = new File(getFilesDir()+ "/somefolder");
Always remember to get the permissions added in the manifest file! 永远记住要在清单文件中添加权限!
This answer might help you even better; 这个答案可能会帮助您更好。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.