简体   繁体   English

Android我想访问我的外部存储文件夹

[英]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; 这个答案可能会帮助您更好。

How to access external storage in android 如何在Android中访问外部存储

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Android Access外部存储 - Android Access External Storage 如何在三星 A51 Android 10 的“内部存储”文件夹(主要外部存储)中创建文件? - How do I create a file in the “Internal Storage” folder (Primary External Storage) of my Samsung A51 Android 10? 我想开发我的 android 代码以在保存到外部存储之前减少从相机捕获的图像文件大小 - I want to develop my android code to reduce the image file size capture from camera before save to external storage Android无法访问外部存储 - Android unable to access external storage 想要访问Android中的通知存储 - Want to access notifications storage in android 有没有一种方法可以在Android上的“我的文件”(外部存储)中创建文件夹并将文件写入此文件夹? - Is there a way to create a folder within My Files on Android (external storage) and write files to this folder? 我想Android存储访问框架中的select文件和文件夹 - I want to select files and folders in the Android storage access framework 我想从外部存储中获取所有文档文件,但在 android 11 中没有管理存储权限 - i want to get all documents file from external storage with out manage storage permission in android 11 无法在 android 上的外部存储上创建文件夹 - Can't create folder on external storage on android Android 在应用程序中打开外部存储文件夹 - Android Open External Storage Folder in app
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM