[英]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.