简体   繁体   English

如何访问 /storage/emulated/0/

[英]How to access /storage/emulated/0/

I have written a code to record audio and save it to below file location.我编写了一个代码来录制音频并将其保存到以下文件位置。

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]);
}

In Logcat, it gives me a file location as在 Logcat 中,它给了我一个文件位置

/storage/emulated/0/AudioRecorder/1436854479696.mp4

I am not able to find this file location on my SD card.我无法在我的 SD 卡上找到这个文件位置。 How to access the location?如何访问该位置?

No need for third party apps无需第三方应用

My Android 6.0 allows me to browse the intern memory without the need for third party apps.我的 Android 6.0 允许我在不需要第三方应用程序的情况下浏览实习生内存。 I simply do this*:我只是这样做*:

  1. "Settings" “设置”
  2. "Storage and USB" “存储和 USB”
  3. "Intern" “实习生”
  4. [let it load a bit...] [让它加载一点...]
  5. [scroll all the way down] [一直向下滚动]
  6. "Browse" “浏览”

* Words may not correspond to the standard English version ones, since I'm just freely translating them from Portuguese. * 单词可能与标准英文版本不符,因为我只是随意从葡萄牙语翻译它们。

Note : At least in my phone, /storage/emulated/0 does not correspond to SD card, but to intern memory .注意:至少在我的手机中, /storage/emulated/0不是对应于 SD 卡,而是对应于intern memory This method did not work for my external card, but I never tried it with another phone.这种方法不适用于我的外置卡,但我从未在其他手机上尝试过。

Hope this helps!希望这可以帮助!

Also you can use Android Debug Bridge (adb) to copy your file from Android device to folder on your PC:您也可以使用Android Debug Bridge (adb)将文件从 Android 设备复制到 PC 上的文件夹:

adb pull /storage/emulated/0/AudioRecorder/1436854479696.mp4 <folder_on_your_PC_e.g. c:/temp>

And you can copy from device whole AudioRecorder folder:您可以从设备的整个AudioRecorder文件夹中复制:

adb pull /storage/emulated/0/AudioRecorder <folder_on_your_PC_e.g. c:/temp>

As Hiren stated, you'll need a file explorer to see your directory.正如 Hiren 所说,您需要一个文件浏览器来查看您的目录。 If you're rooted I highly suggest root explorer, otherwise ES File Explorer is a good choice.如果你已经 root,我强烈建议你使用 root explorer,否则 ES File Explorer 是一个不错的选择。

Plug in your device and run adb shell which will get you a command shell on your device.插入您的设备并运行adb shell ,这将在您的设备上获得一个命令 shell。 You don't have permission to read /storage/emulated/ but since you know it's in subdirectory 0 just go cd /storage/emulated/0 and you will be able to look around and interact as aspected.您无权读取/storage/emulated/但因为您知道它在子目录 0 中,只需转到cd /storage/emulated/0就可以环顾四周并按方面进行交互。

Note: you can use adb wirelessly as well注意:您也可以无线使用adb

Try This尝试这个

private String getFilename() {
    String filepath = Environment.getExternalStorageDirectory().getPath();
    File file = new File(filepath + "/AudioRecorder" );
    if (!file.exists()) {
        file.mkdirs();
    }
    return (file.getAbsolutePath() + "/" + System.currentTimeMillis() + ".mp4");
}

In Emulator, to view this file click on Settings>Storage>Other>Android>data>com.companyname.textapp>file>Download.在模拟器中,点击设置>存储>其他>Android>数据>com.companyname.textapp>文件>下载来查看这个文件。 Here, textapp is the name of the app you are working on.在这里, textapp 是您正在处理的应用程序的名称。

https://productforums.google.com/forum/#!msg/nexus/WIcHUNQfRLU/ALpViG86AwAJ https://productforums.google.com/forum/#!msg/nexus/WIcHUNQfRLU/ALpViG86AwAJ

Mr Expensive Toys said: Am amazed that this problem is still showing up as it started happening as far back as Honeycomb.昂贵的玩具先生说: 我很惊讶这个问题仍然出现,因为它早在 Honeycomb 就开始发生了。

So, the /storage/emulated/0/DCIM/Camera is the same folder as your normal DCIM/Camera folder.因此,/storage/emulated/0/DCIM/Camera 与正常的 DCIM/Camera 文件夹是同一个文件夹。 Its just a symlink.它只是一个符号链接。 So the files are actually in the right location you just have an app that put bad data into the MediaStore Database.所以这些文件实际上位于正确的位置,您只是有一个将不良数据放入 MediaStore 数据库的应用程序。

When accessing files from your PC your are actually enumerating the MediaStorage database for files.从您的 PC 访问文件时,您实际上是在为文件枚举 MediaStorage 数据库。 Its not pulling a traditional directory lists.它不是拉传统的目录列表。 So what you see is based on what is in that database and the path entries in the database.因此,您看到的内容基于该数据库中的内容以及数据库中的路径条目。 Files in the database pointing to emulated directories aren't shown as they are assumed to be duplicates as its the same physical directory as your normal DCIM/Camera.数据库中指向模拟目录的文件不会显示,因为它们被认为是重复的,因为它与普通 DCIM/相机的物理目录相同。 What is going on is that some poorly written third party apps are inserting entries into the database with the /storage/emulated/0/DCIM/Camera path instead of the proper root path to DCIM/Camera.正在发生的事情是,一些编写不佳的第三方应用程序正在使用 /storage/emulated/0/DCIM/Camera 路径而不是 DCIM/Camera 的正确根路径将条目插入到数据库中。 Which means that the MTP service can't see them when you are hooked up to your PC.这意味着当您连接到 PC 时,MTP 服务无法看到它们。

Usually the easiest way to fix the problem is to just clear the MediaStore databases to get the bad entries out of the MediaStore Database and let the system reindex the files and put into the database with the proper paths.通常解决问题的最简单方法是清除 MediaStore 数据库以从 MediaStore 数据库中取出错误条目,并让系统重新索引文件并以正确的路径放入数据库。

Settings->apps Hit 3 dot menu in top right and select Show System Find Media Storage, Select it, Select Storage, then Clear Data Find External Storage, Select it , Select Storage, then Clear Data Turn phone off, turn phone back on, wait for indexer service to rebuild the data.设置->应用点击右上角的 3 点菜单并选择显示系统查找媒体存储,选择它,选择存储,然后清除数据查找外部存储,选择它,选择存储,然后清除数据关闭手机,重新打开手机,等待索引器服务重建数据。

When you are done the files should show up with proper directory tree and be visible from the PC.完成后,文件应该显示在正确的目录树中,并且可以从 PC 上看到。 Depending on amount of files on the phone it can take as 10-20 minutes to rebuild the media database as the service walks the phone directories, getting meta data, creating thumbnails, etc.根据手机上的文件数量,重建媒体数据库可能需要 10-20 分钟,因为服务会遍历手机目录、获取元数据、创建缩略图等。

在这里,它位于 /mnt/shell/emulated/0

Android recommends that you call Environment.getExternalStorageDirectory.getPath() instead of hardcoding /sdcard/ in path name. Android 建议您在路径名中调用Environment.getExternalStorageDirectory.getPath()而不是硬编码/sdcard/ This returns the primary shared/external storage directory.这将返回主共享/外部存储目录。 So, if storage is emulated, this will return /storage/emulated/0 .所以,如果存储被模拟,这将返回/storage/emulated/0 If you explore the device storage with a file explorer, the said directory will be /mnt/sdcard (confirmed on Xperia Z2 running Android 6).如果您使用文件浏览器浏览设备存储,则所述目录将为/mnt/sdcard (在运行 Android 6 的 Xperia Z2 上确认)。

Try it from试试从

ftp://ip_my_s5:2221/mnt/sdcard/Pictures/Screenshots

which point onto /storage/emulated/0指向/storage/emulated/0

In my case, /storage/emulated/0/ corresponds to my device's root path .就我而言, /storage/emulated/0/ 对应于我设备的根路径 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例如,当我使用手机的默认相机应用程序拍照时,图像会自动保存/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.例如,假设您想将您的图片存储在/Pictures 目录中,即根目录中存在的Pictures 目录中。 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.如果要将图像保存在 DCIM 或下载目录中,请为上面显示的 Environment.getExternalStoragePublicDirectory() 方法提供以下参数。

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
);

If you are using a simulator in Android Studio on Mac you can go to View -> Tool Windows -> Device File Explorer .如果您在 Mac 上的 Android Studio 中使用模拟器,您可以转到View -> Tool Windows -> Device File Explorer Here you can use a finder-like structure.在这里,您可以使用类似 finder 的结构。

if you are using Android device monitor and android emulator : I have accessed following way: Data/Media/0/如果您使用的是 Android 设备监视器和 android 模拟器:我已通过以下方式访问:Data/Media/0/ 在此处输入图片说明

To RESTORE your pictures from /storage/emulated/0/ simply open the 100Andro file..there you will see your pictures although you may not have access to them in you pc explorer.要从 /storage/emulated/0/ 恢复您的图片,只需打开 100Andro 文件..在那里您将看到您的图片,尽管您可能无法在您的 PC 资源管理器中访问它们。 There open each picture one by one, go on setting (three dots..) and save the picture.将每张图片一张一张打开,继续设置(三个点..)并保存图片。 It will show up in the android file 'Pictures' from where you can also copy them by using your explorer.它将显示在 android 文件“图片”中,您也可以使用资源管理器从中复制它们。 There is no 'save all' function, however so it must be done one by one, but it works.没有“全部保存”功能,因此必须一一完成,但它有效。

QT QT

View On-Device Files with Device File Explorer使用设备文件资源管理器查看设备文件

https://developer.android.com/studio/debug/device-file-explorer https://developer.android.com/studio/debug/device-file-explorer

for Xamarin Android适用于 Xamarin Android

Using command //get the file directory使用命令 //获取文件目录

Image image =new Image() { Source = file.Path };

then in command adb pull //the image file path here然后在命令 adb pull //这里的图像文件路径

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM