我将创建一个 c# windows 应用程序,用于将图像文件从 android 手机传输到我的 Wondows PC - 当我将手机与我的 PC 连接时(使用数据线)。当我在 C# 中指定路径“Computer/Nuxes5/...”以从移动设备访问文件时,(从 Windows 资源管理器地址栏中获取)。然后得到不正确的路径。以下是我提供的用于访问文件的代码。
Directory.GetFiles(@"Computer/Nuxes5/...");
Run Code Online (Sandbox Code Playgroud)
任何人都可以建议我如何使用 C# 访问移动文件。
我试图在Windows 7上获取所有USB设备(包括便携式设备),现在我搜遍了所有并没有找到一个好的答案.
我试过这段代码:
static void Main(string[] args)
{
//
// Get an instance of the device manager
//
PortableDeviceApiLib.PortableDeviceManagerClass devMgr
= new PortableDeviceApiLib.PortableDeviceManagerClass();
//
// Probe for number of devices
//
uint cDevices = 1;
devMgr.GetDevices(null, ref cDevices);
//
// Re-allocate if needed
//
if (cDevices > 0)
{
string[] deviceIDs = new string[cDevices];
devMgr.GetDevices(deviceIDs, ref cDevices);
for (int ndxDevices = 0; ndxDevices < cDevices; ndxDevices++)
{
Console.WriteLine("Device[{0}]: {1}",
ndxDevices + 1, deviceIDs[ndxDevices]);
}
}
else
{
Console.WriteLine("No WPD devices …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用此代码段将内容传输到便携式设备
IPortableDeviceValues values =
GetRequiredPropertiesForContentType(fileName, parentObjectId);
IStream tempStream;
uint optimalTransferSizeBytes = 0;
content.CreateObjectWithPropertiesAndData(
values,
out tempStream,
ref optimalTransferSizeBytes,
null);
System.Runtime.InteropServices.ComTypes.IStream targetStream =
(System.Runtime.InteropServices.ComTypes.IStream)tempStream;
try
{
using (var sourceStream =
new FileStream(fileName, FileMode.Open, FileAccess.Read))
{
var buffer = new byte[optimalTransferSizeBytes];
int bytesRead;
do
{
bytesRead = sourceStream.Read(
buffer, 0, (int)optimalTransferSizeBytes);
IntPtr pcbWritten = IntPtr.Zero;
if (bytesRead < (int)optimalTransferSizeBytes)
{
targetStream.Write(buffer, bytesRead, pcbWritten);
}
else
{
targetStream.Write(buffer, (int)optimalTransferSizeBytes, pcbWritten);
}
} while (bytesRead > 0);
}
targetStream.Commit(0);
}
finally
{
System.Runtime.InteropServices.Marshal.ReleaseComObject(tempStream);
} …Run Code Online (Sandbox Code Playgroud) WPD在Windows XP上无法正常工作(如果重要的话,SP1),即使微软声明它也是如此.
WPD问题:
IPortableDeviceManager.GetDevices 在Windows 7上找到所有连接的摄像头时,调用在Win XP上找不到任何设备.
其他一些人也有同样的问题,WPD没有在XP上工作,没有解决方案: 1 2
我决定使用WIA重新实现功能.
WIA自动化/ WIA接口出现问题:
WIA automation 在与相机交互时只提供愚蠢的对话 - 我需要从代码中做到这一点WIA interfaces建议使用WIA 编程来实现较低级别的任务.我没有找到任何样本如何使用C#的WIA接口(也发现一些迹象表明这根本不可能或至少很难做到)因此,我查看了WIA 2.0(wiaaut.dll包装器):
我在这里没有选择... 你能推荐一种替代方案,为连接到适用于Windows XP的计算机的摄像机提供以下功能吗?
我有一个桌面java应用程序,也是一个Android应用程序.两个app一起工作.
桌面应用程序中的用户有一个按钮来启动设备数据应用程序与计算机应用程序之间的传输,反之亦然.
所以我需要用简单的USB线传输数据,没有互联网连接/ WiFi /蓝牙/ adb.
我找到两个可以在Windows上运行的Java MTP库来解决我的问题,以及android的USB Host/accesory功能:
jMTP成功识别我的Android设备,文件夹和其他内容
我成功地在计算机--->设备中传输文件,但是当我尝试在设备中传输文件时出错 - >计算机
在解释之后我把我的代码.
jusbpmp但我没有可能转移设备--->电脑.
USB主机/附件无用,因为传输是从桌面应用程序启动的,当我在android开发者指南网站上阅读时,它似乎与我需要的不一致,或者可能是用户从设备开始传输.
我尝试从1周到成功完成这项任务,但似乎我需要帮助.
Java + jMTP代码
private static void jMTPeMethode()
{
PortableDeviceManager manager = new PortableDeviceManager();
PortableDevice device = manager.getDevices()[0];
// Connect to USB tablet
device.open();
System.out.println(device.getModel());
System.out.println("---------------");
// Iterate over deviceObjects
for (PortableDeviceObject object : device.getRootObjects())
{
// If the object is a storage object
if (object instanceof PortableDeviceStorageObject)
{
PortableDeviceStorageObject storage = (PortableDeviceStorageObject) object;
for (PortableDeviceObject o2 : storage.getChildObjects())
{
if(o2.getOriginalFileName().equalsIgnoreCase("Test")) …Run Code Online (Sandbox Code Playgroud) 是否有任何可用于 VB.net 的库使我能够轻松访问 MTP 设备?我希望能够找出连接了哪些设备,列出它们的内容并将文件复制到它们或从它们复制文件。
到目前为止,我看到的所有内容(在 Stack Overflow、Microsoft 网站上或通过简单的 Google 搜索)都是使用 C++、C# 或其他非 VB.net 语言编写的。Microsoft 文档完全超出了我的理解。
结果,除非我打算学习一门新语言,否则一切都不是入门。
我确实找到了MTPSharp,这给了我希望。但是没有文档,它似乎没有完全实现,我尝试做某些事情会返回一个异常,作者告诉我它是针对我不应该使用的旧 API 编写的,并且无法帮助我解决我有问题。
想要使用VB.net的人真的没有希望吗?
wpd ×6
c# ×4
mtp ×3
android ×2
usb ×2
.net ×1
connection ×1
dll ×1
exception ×1
java ×1
vb.net ×1
wia ×1
windows-10 ×1
windows-xp ×1