Accessing android devices in C#

2019-02-15 13:18发布

I am using MAD-Bee(Managed ADB) library to access ADB in C#. I am just trying to get list of devices attached to PC. I am getting list of devices properly when I use ADB from command prompt, but I get 0 in my C# form.
Here's the code I've tried -

    AndroidDebugBridge mADB;
    String mAdbPath;
    IList<Device> mDeviceList = null;
    public Form1()
    {
        InitializeComponent();
        mAdbPath = Environment.GetEnvironmentVariable("ANDROID_ROOT");
        mADB = AndroidDebugBridge.CreateBridge(mAdbPath + "\\platform-tools\\adb.exe", true);
        mADB.Start();

        var list = mADB.Devices;
        Console.WriteLine(""+list.Count);
    }

The problem is MAD-bee doesn't have any proper documentation or guide on how to start with it. Any help in this?

2条回答
淡お忘
2楼-- · 2019-02-15 14:00

I would like to suggest you use another library in C# for your application.

I found AndroidLib.dll on XDA which has provided a way of interfacing my C# application.

The Thread can be found here:

http://forum.xda-developers.com/showthread.php?t=1512685

He has a GITHUB for the source and in the GITHUB he has example projects in Visual Studio solutions files to learn from as well as detailed usage.

查看更多
甜甜的少女心
3楼-- · 2019-02-15 14:03

Woops found it now -

List<Device> devices = AdbHelper.Instance.GetDevices ( AndroidDebugBridge.SocketAddress );

More information is available in these tests -

MadBee Tests

查看更多
登录 后发表回答