6

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.

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

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.

Cœur
  • 37,241
  • 25
  • 195
  • 267
Brian Tacker
  • 1,091
  • 2
  • 18
  • 37
  • 1
    I would go with solution #3. this link might be helpful http://stackoverflow.com/questions/123927/how-to-find-usb-drive-letter – Loman Nov 09 '11 at 22:34
  • 2
    You do not need to install the complete SDK to use ADB operations. Since you're going to be deploying this to multiple systems, you can package adb.exe,AdbWinApi.dll, AdbWinUsbApi.dll (Windows files.. If you're using Linux modify accordingly. Since C# I assume windows) in a zip file and write your code that calls the ADB methods to extract your files – dymmeh Nov 09 '11 at 22:42
  • Thank you for the suggestions. I will try them and see which one works best in my situation. – Brian Tacker Nov 10 '11 at 02:24

1 Answers1

-1

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;
Aaron Anodide
  • 16,906
  • 15
  • 62
  • 121
  • This is definitely helpful but the drives name is just "Removable Disk" so the d.Name.Contains("android") would always return false. So maybe I can just check if its the only removable drive and if not prompt the user to choose the correct one. – Brian Tacker Nov 10 '11 at 02:33
  • android is the name of a folder at the top level of the removable drive - so if every android drive had a folder containing the word "android" you'd find it - it's not a deterministic solution but ithought it was a start – Aaron Anodide Nov 10 '11 at 02:35
  • O ok i see what your saying, I suppose if there is no folder that contains "android" I can always just create one so the drive can be identified. Thank you for the suggestion. – Brian Tacker Nov 10 '11 at 14:06
  • 2
    Android devices are listed in portable drives, not in removable drives. When we get removable drives the c# does not include android mobile's drives in results. I tried to get all drives of pc, still mobile storage is missing in result. – Ahmad Raza Aug 27 '13 at 18:58
  • @AhmadRaza: This is exactly my problem...have you found a solution to access those files which are stored on a "Portable Device"? – Chris623 Dec 10 '13 at 07:48
  • 4
    @Chris623: yes i got the solution, Check this library, Its awesome :) http://forum.xda-developers.com/showthread.php?t=1512685 – Ahmad Raza Dec 10 '13 at 13:54