简体   繁体   English

如何在Android中获取所有内存路径(内部或外部内存)列表

[英]How to Get All Memory Path (Internal or External Memory) list in android

I'm facing problem to detect all memory path in Android device. 我在检测Android设备中的所有内存路径时遇到问题。 If we try with provide tips and example we aren't able to getting proper external memory path. 如果尝试提供提示和示例,我们将无法获得正确的外部存储路径。

For Example : 例如 :

If we try to get external memory in Samsung Tab 2 Used code :: 如果我们尝试在Samsung Tab 2中使用外部存储器,请使用代码::

Environment.getExternalStorageDirectory().getAbsolutePath() Environment.getExternalStorageDirectory()。getAbsolutePath()

It will provide us internal Mounted Memory path. 它将为我们提供内部安装的内存路径。 //storage/sdcard0/ // storage / sdcard0 /

After lot of googling i found one application which show all path of device 经过大量的搜索后,我发现了一个显示设备所有路径的应用程序

Application Name " ES Explorer " This application showing all path of Memory. 应用程序名称“ ES Explorer ”此应用程序显示内存的所有路径。

Please provide us any solution so we can fix our problem 请提供任何解决方案,以便我们解决问题

Beyond those types of storage volumes specifically supported by the standard Android SDK is a wide variety of vendor- and version- unique possibilities. 除了标准Android SDK特别支持的那些类型的存储卷之外,还有各种不同的供应商和版本独有的可能性。

You can find all mounted filesystems by reading /proc/mounts as a text file. 您可以通过将/proc/mounts读取为文本文件来找到所有已挂载的文件系统。

However: 然而:

  • This will only find filesystems which are actually mounted - for example, it will not find USB storage volumes if they are handled as arbitrary USB accessories by an application, rather than mounted by the Linux operating system underlying Android. 这只会找到实际安装的文件系统-例如,如果USB存储卷由应用程序作为任意USB附件处理,而不是由Android底层的Linux操作系统安装,则找不到USB存储卷。

  • You will have to apply some logic to filter out all the other various file systems which are not general storage devices and show up in the list. 您将必须应用一些逻辑来过滤掉不是通用存储设备的所有其他各种文件系统,并显示在列表中。 It used to be that you could detect "external" storage volumes by looking for "vfat" as a type, but that is no longer used in recent Android versions 过去,您可以通过查找"vfat"作为类型来检测“外部”存储卷,但是在最近的Android版本中不再使用

  • Especially in recent Android versions, the actual path of the mount as discovered from /proc/mounts and the path customarily used may not match, as the customary path may redirect to the actual one by multiple levels of symbolic links 特别是在最新的Android版本中,从/proc/mounts发现的安装的实际路径与习惯使用的路径可能不匹配,因为习惯路径可能会通过多个级别的符号链接重定向到实际路径

Samsung handles their storage a little differently than some other devices unfortunately. 不幸的是,三星在存储方面的处理方式与其他一些设备有所不同。 Ever since their version of Android 3.2, they have also disallowed the writing to the external storage by regular apps. 自从发布Android 3.2版本以来,他们还禁止常规应用程序将其写入外部存储。 That being said, you can still read(access) the external storages. 话虽如此,您仍然可以读取(访问)外部存储。 Below are the paths to the two possible external storage locations. 以下是两个可能的外部存储位置的路径。 I actually have programmed specifically for the Galaxy Tab 2.0 (7 inch), so here ya go: 我实际上已经专门为Galaxy Tab 2.0(7英寸)编程,所以这里开始吧:

Inserted microSD card: mnt/extSdCard 插入的microSD卡: mnt/extSdCard
Connected external storage via Samsung USB Adapter: mnt/UsbDriveA 通过三星USB适配器连接的外部存储: mnt/UsbDriveA
"sdcard" storage(not an inserted SD card): getExternalStorageDirectory() as you know. “ sdcard”存储(不是插入的SD卡):您知道的getExternalStorageDirectory()

I've tried multiple ways to use functions to find the path, but haven't had any luck ever. 我尝试了多种方法来使用函数来查找路径,但从未有过运气。 However, this works, so I'm content. 但是,这可行,所以我很满意。 I hope it can help you too. 我希望它能对您有所帮助。

Please try to use bellow code. 请尝试使用以下代码。

public static File FileCache(Context context) {
    // Find the dir to save cached images
    File cacheDir;
    if (android.os.Environment.getExternalStorageState().equals(
            android.os.Environment.MEDIA_MOUNTED))
        cacheDir = new File(
                android.os.Environment.getExternalStorageDirectory(),
                "TechTool_Pdf");
    else
        cacheDir = context.getCacheDir();
    if (!cacheDir.exists())
        cacheDir.mkdirs();
    return cacheDir;
}

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

相关问题 在 android 中,如何获取所有已安装的外部 memory 的列表 - In android how can I get a list of all external memory installed Android 获取内部/外部内存的可用大小 - Android get free size of internal/external memory Android内部存储器路径 - Android internal memory path 如何在android中获取原始文件夹uri路径并保存在内部存储器中? - how to get raw folder uri path and save in internal memory in android? 获取用户选择的文件的名称和路径,而不管其在 Android 中的位置[在内部或外部 memory 中]? - Get the user selected file's name and path irrespective of its location [ either in internal or external memory ] in Android? 访问android中的内部/外部内存 - Accessing internal/external memory in android "如何在android中获取内部和外部sdcard路径" - How to get the internal and external sdcard path in android 如何从外部sdcard和手机存储中获取所有文件(移动存储内部)? - How to get all files from external sdcard and phone storage (internal with mobile memory)? 在Android中使用绝对路径获取内部和外部存储中所有文件(每个文件)的列表 - Get list of all files (every file) in both internal and external storage with absolute path in Android Android如何将包含文件的文件夹从内部存储器复制到外部 - Android how to copy folder with files on it from Internal memory to External
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM