windows 从 PC 以编程方式访问 android 设备上的文件

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/8072650/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 18:26:08  来源:igfitidea点击:

Programmatically access files on android device from PC

c#androidwindows

提问by Brian Tacker

I have a C# application that will need to access files that are on my android tablet, obviously I can just use the mounted drive letter for the storage but I will be deploying this at multiple locations and need a consistent way to access the files. I'm able to call ADB programmatically, but again, I am deploying it at multiple locations and can't install the SDK on every system.

我有一个 C# 应用程序需要访问我的 android 平板电脑上的文件,显然我可以只使用安装的驱动器号进行存储,但我将在多个位置部署它并且需要一种一致的方式来访问文件。我能够以编程方式调用 ADB,但同样,我将它部署在多个位置并且无法在每个系统上安装 SDK。

So I guess I'm looking to either: 1) programmaticaly access the device using C# (or java) or 2) Use ADB without having to install the SDK at each location or 3) Find out the drive letter of the attached device programmatically

所以我想我正在寻找:1) 使用 C#(或 java)以编程方式访问设备或 2) 使用 ADB 而不必在每个位置安装 SDK 或 3) 以编程方式找出连接设备的驱动器号

As you could have guessed I'm trying to make this as seamless as possible

正如您可能已经猜到的那样,我正在努力使其尽可能无缝

P.S. An example of an application that works this way is HTC Sync, If anyone knows how that application does it that would be perfect.

PS 以这种方式工作的应用程序的一个例子是 HTC Sync,如果有人知道该应用程序是如何做到的,那就太完美了。

采纳答案by Aaron Anodide

Here's what I came up with for you to maybe start with.

这是我想出来的,也许你可以从这里开始。

var drives = DriveInfo.GetDrives();

var removableFatDrives = drives.Where(
        c=>c.DriveType == DriveType.Removable &&
        c.DriveFormat == "FAT" && 
        c.IsReady);

var andriods = from c in removableFatDrives
               from d in c.RootDirectory.EnumerateDirectories()
               where d.Name.Contains("android")
               select c;