TL;DR:使用获取外部SD卡详细信息() https://github.com/dpa99c/cordova-diagnostic-plugin#getexternalsdcarddetails函数来自科尔多瓦诊断插件 https://github.com/dpa99c/cordova-diagnostic-plugin#getexternalsdcarddetails.
返回的“外部目录”cordova-plugin-file
对应于不可移动(内部)存储。
这是因为这些模拟位置保证始终存在于所有 Android 设备上,而并非所有硬件供应商都支持外部/可移动 SD 卡位置,它们是制造商/Android 版本特定的,并且如果外部 SD 卡可能不存在未插入读卡器。
例如,在运行 Android 7.1.1 的 Samsung Galaxy S4 上:
-
cordova.file.externalRootDirectory
回报file:///storage/emulated/0/
-
cordova.file.externalApplicationStorageDirectory
回报file:///storage/emulated/0/Android/data/cordova.plugins.diagnostic.example/
它们是不可移动内部存储上的文件路径。
相比之下,获取外部SD卡详细信息() https://github.com/dpa99c/cordova-diagnostic-plugin#getexternalsdcarddetails函数来自科尔多瓦诊断插件 https://github.com/dpa99c/cordova-diagnostic-plugin#getexternalsdcarddetails返回可移动外部 SD 卡的位置和详细信息。
例如,在运行 Android 7.1.1 的 Samsung Galaxy S4 上,它返回:
[{
"path": "/storage/4975-1401/Android/data/cordova.plugins.diagnostic.example/files",
"filePath": "file:///storage/4975-1401/Android/data/cordova.plugins.diagnostic.example/files",
"canWrite": true,
"freeSpace": 16254009344,
"type": "application"
}, {
"path": "/storage/4975-1401",
"filePath": "file:///storage/4975-1401",
"canWrite": false,
"freeSpace": 16254009344,
"type": "root"
}]
它们是外部可移动存储上的文件路径。