Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/315.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 安卓SD卡路径概要_Java_Android_File Io - Fatal编程技术网

Java 安卓SD卡路径概要

Java 安卓SD卡路径概要,java,android,file-io,Java,Android,File Io,我有一个有点奇怪的问题:这次一切正常,但我不明白为什么 这样就可以安装多个sd卡了。所有内容都将装入/mnt目录。(这是真的吗?) 在我的设备上,只有一个sd卡安装在/mnt/sdcard上。在我的应用程序中,我从中打开文件。我正在使用下一个代码: private void open() { // get file extension String extension = ""; int dotIndex = downloadedFile.

我有一个有点奇怪的问题:这次一切正常,但我不明白为什么

这样就可以安装多个sd卡了。所有内容都将装入
/mnt
目录。(这是真的吗?)

在我的设备上,只有一个sd卡安装在
/mnt/sdcard
上。在我的应用程序中,我从中打开文件。我正在使用下一个代码:

    private void open() {
        // get file extension
        String extension = "";
        int dotIndex = downloadedFile.lastIndexOf('.');
        if (dotIndex != -1) {
            extension = downloadedFile.substring(dotIndex + 1, downloadedFile.length());
        }

        // create an intent
        Intent intent = new Intent(android.content.Intent.ACTION_VIEW);
        Uri data = Uri.fromFile(new File(downloadedFile));
        String type = MimeTypeMap.getSingleton().getMimeTypeFromExtension(extension);
        if (type == null || type.length() == 0) {
            // if there is no acceptable mime type
            type = "application/octet-stream";
        }
        intent.setDataAndType(data, type);

        // get the list of the activities which can open the file
        List resolvers = context.getPackageManager().queryIntentActivities(intent, PackageManager.MATCH_DEFAULT_ONLY);
        if (resolvers.isEmpty()) {
            (new AlertDialog.Builder(context)
                    .setMessage(R.string.AttachmentUnknownFileType)
                    .setNeutralButton(R.string.NeutralButtonText, null)
                    .create()).show();
        } else {
            context.startActivity(intent);
        }
    }
实际上
downloaddedfile
变量的值类似于
file:///sdcard/mydir/myfile.txt
。但代码是有效的。为什么?Android如何理解
/sdcard/..
/mnt/sdcard/..
相同的内容

主要问题:如果sd卡将被安装到其他目录(对于exmaple,
/mnt/other sd/
甚至
/media/sd
),会发生什么情况?如果要挂载多张sd卡怎么办:android如何理解要使用哪张卡


谢谢你的帮助!祝你有愉快的一天

很简单,安卓在手机开机时通过设置文件配置挂载,因此如果有mor SD卡,安卓只会选择其中一个设置为

/SD卡/

因此,当挂载设置更改时,您的代码完全无用,您只能希望这些设置不会被更改。
每一家生产安卓智能手机的公司都使用“SD卡”路径,甚至像use这样的定制ROM也使用它

文件夹的不同路径如何?为什么路径
file:///sdcard/
/mnt/sdcard
相同吗?