C# 如何管理MTP便携式设备上的文件?
我已经研究这个主题好几天了,但我找不到任何关于在MTP便携式设备(更具体地说是Galaxy S4)上管理文件的内容 我想能够C# 如何管理MTP便携式设备上的文件?,c#,android,mtp,C#,Android,Mtp,我已经研究这个主题好几天了,但我找不到任何关于在MTP便携式设备(更具体地说是Galaxy S4)上管理文件的内容 我想能够 将文件从PC复制到MTP设备 将文件从MTP设备复制到PC 从MTP设备中删除文件 我真的很想复制MP3文件,但如果有一个通用的方法来复制和MTP支持的文件,这将是可怕的。我查看了Windows Portable Device API,但在C#中找不到任何地方有示例代码 任何博客、示例代码和文件都会非常有用。谢谢!:) 我使用了一个名为 这使得我很容易将我的照片从an
- 将文件从PC复制到MTP设备
- 将文件从MTP设备复制到PC
- 从MTP设备中删除文件
任何博客、示例代码和文件都会非常有用。谢谢!:) 我使用了一个名为 这使得我很容易将我的照片从android手机复制到电脑上
public class Program
{
static void Main(string[] args)
{
var devices = MediaDevice.GetDevices();
using (var device = devices.First(d => d.FriendlyName == "Galaxy Note8"))
{
device.Connect();
var photoDir = device.GetDirectoryInfo(@"\Phone\DCIM\Camera");
var files = photoDir.EnumerateFiles("*.*", SearchOption.AllDirectories);
foreach (var file in files)
{
MemoryStream memoryStream = new System.IO.MemoryStream();
device.DownloadFile(file.FullName, memoryStream);
memoryStream.Position = 0;
WriteSreamToDisk($@"D:\PHOTOS\{file.Name}", memoryStream);
}
device.Disconnect();
}
}
static void WriteSreamToDisk(string filePath, MemoryStream memoryStream)
{
using (FileStream file = new FileStream(filePath, FileMode.Create, System.IO.FileAccess.Write))
{
byte[] bytes = new byte[memoryStream.Length];
memoryStream.Read(bytes, 0, (int)memoryStream.Length);
file.Write(bytes, 0, bytes.Length);
memoryStream.Close();
}
}
}
还有一个名为WPDApi的nuget软件包,在我设法下载源代码(nuget有问题)后,它对我很有效:
嗨,克里斯,你有什么解决方案吗?没有,我在研究Windows SDK,但不知道如何在我的项目中实现它。