0

ちょっと変わった質問があります。今回はすべてうまくいきましたが、その理由がわかりません。

私の知る限り、複数のSDカードをマウントすることは可能です。すべてが/mntディレクトリにマウントされます。(本当ですか?)

私のデバイスには、にマウントされた sd カードが 1 つしかありません/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);
        }
    }

実際downloadedFile、変数には のような値がありますfile:///sdcard/mydir/myfile.txt。しかし、コードは機能します。なんで?/sdcard/...Androidは と同じものをどのように理解し/mnt/sdcard/...ますか?

そして主な質問: SD カードが他のディレクトリ (たとえば、/mnt/another-sd/または/media/sd) にマウントされるとどうなりますか? 複数の SD カードがマウントされる場合はどうなりますか: Android はどのカードを使用するかをどのように理解しますか?

助けてくれてありがとう!良い一日を過ごしてください!

4

1 に答える 1

0

シンプルなAndroidは、電話の起動時に設定ファイルをマウントするように構成しているため、mor sdcardがある場合、Androidはそれらの1つを次のように設定することを選択します。

/SDカード/

したがって、マウント設定が変更された場合、コードは単に役に立たず、設定が変更されていないことを期待できます。Androidスマートフォンを調達するすべての企業は、「sdcard」パスを使用します。

于 2012-06-09T10:51:28.857 に答える