ちょっと変わった質問があります。今回はすべてうまくいきましたが、その理由がわかりません。
私の知る限り、複数の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 はどのカードを使用するかをどのように理解しますか?
助けてくれてありがとう!良い一日を過ごしてください!