How to access /storage/emulated/0/

前端 未结 16 2256
被撕碎了的回忆
被撕碎了的回忆 2020-12-13 01:53

I have written a code to record audio and save it to below file location.

private String getFilename() {
    String          


        
16条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-13 02:48

    In my case, /storage/emulated/0/ corresponds to my device's root path. For example, when i take a photo with my phone's default camera application, the images are saved automatically /store/emulated/0/DCIM/Camera/mypicname.jpeg

    For example, suppose that you want to store your pictures in /Pictures directory, namely in Pictures directory which exist in root directory. So you use the below code.

    File storageDir = Environment.getExternalStoragePublicDirectory( Environment.DIRECTORY_PICTURES );
    

    If you want to save the images in DCIM or Downloads directory, give the below arguments to the Environment.getExternalStoragePublicDirectory() method shown above.

    Environment.DIRECTORY_DCIM
    Environment.DIRECTORY_Downloads
    

    Then specify your image name :

    String imageFileName = "JPEG_" + timeStamp + "_";
    

    Then create the file object as shown below. You specify the suffix as the 2nd argument.

    File image = File.createTempFile(
                imageFileName,  // prefix
                ".jpg",         // suffix
                storageDir      // directory
    );
    

提交回复
热议问题