[英]Android SD card path synonims
我有一个奇怪的问题:这次一切正常,但我不明白为什么。
AFAIK可以安装多个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);
}
}
实际上downloadedFile
变量的值类似于file:///sdcard/mydir/myfile.txt
。 但是代码有效。 为什么? Android如何了解/sdcard/...
与/mnt/sdcard/...
?
主要问题:如果将SD卡安装到其他目录(例如, /mnt/another-sd/
甚至是/media/sd
),会发生什么? 如果将安装多个SD卡,该怎么办:Android如何了解要使用的卡?
感谢您的任何帮助! 祝你有美好的一天!
这是简单的android配置在电话启动时通过设置文件进行挂载的功能,因此,如果有更多的sdcard,Android只会选择其中一个设置为
/SD卡/
因此当挂载设置更改您的代码时根本没有用,您只能希望设置保持不变。 每家生产Android智能手机的公司都使用“ sdcard”路径,甚至像定制rom一样使用它
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.