Windows Phone 8 新增加了对 SD 卡的支持,开发者可以直接访问SD卡非加密的内容,但无法执行Write操作
而且用户可以将已通过审核的应用拷贝到SD上进行安装,只是在安装的过程中需要用户手机联网到marketplace上进行验证,如果是合法程序则可以直接安装使用。
代码中对SD卡操作需要添加 ID_CAP_REMOVABLE_STORAGE 能力,
使用代码片段,引用自官方Route mapper sample例子,完整例子请移步到:点击打开链接
// Process a route from the SD card.
private async Task ProcessSDGPXFile(string _sdFilePath)
{
// Connect to the current SD card.
ExternalStorageDevice sdCard = (await ExternalStorage.GetExternalStorageDevicesAsync()).FirstOrDefault();
// If the SD card is present, get the route from the SD card.
if (sdCard != null)
{
try
{
// Get the route (.GPX file) from the SD card.
ExternalStorageFile file = await sdCard.GetFileAsync(_sdFilePath);
// Create a stream for the route.
Stream s = await file.OpenForReadAsync();
// Read the route data.
ReadGPXFile(s);
}
catch (FileNotFoundException)
{
// The route is not present on the SD card.
MessageBox.Show("That route is missing on your SD card.");
}
}
else
{
// No SD card is present.
MessageBox.Show("The SD card is mssing. Insert an SD card that has a Routes folder containing at least one .GPX file and try again.");
}
}