Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to construct a DeviceClient #91

Open
itapi opened this issue Feb 11, 2024 · 4 comments
Open

How to construct a DeviceClient #91

itapi opened this issue Feb 11, 2024 · 4 comments
Labels
help wanted Extra attention is needed

Comments

@itapi
Copy link

itapi commented Feb 11, 2024

What can we do for you?

I want to listen to a device connection,but I don't know how to obtain a "DeviceClient" object,so I can execute actions on it...I have the DeviceData but it doesn't help me much...

public async Task Start()
{
    StartServerResult startServerResult = await AdbServer.Instance.StartServerAsync(@"C:\Users\laptop\AppData\Local\Android\Sdk\platform-tools\adb.exe", false, CancellationToken.None);
    Trace.WriteLine(startServerResult); // result is already running

   
    DeviceMonitor deviceMonitor = null;

    deviceMonitor = new DeviceMonitor(new AdbSocket(new IPEndPoint(IPAddress.Loopback, AdbClient.AdbServerPort)));
    deviceMonitor.DeviceConnected += (sender, e) =>

    {
        Trace.WriteLine($"Device connected: {e.Device}");

        //need to obtain a DeviceClient object,to execute a swipe method.
             

    };
    deviceMonitor.DeviceDisconnected += (sender, e) => Trace.WriteLine($"Device disconnected: {e.Device}");
    deviceMonitor.DeviceChanged += (sender, e) => Trace.WriteLine($"Device state changed: {e.Device} {e.OldState} -> {e.NewState}");

    await deviceMonitor.StartAsync();

    // Additional code if needed
}
@itapi itapi added the help wanted Extra attention is needed label Feb 11, 2024
@wherewhere
Copy link
Member

Screenshot_20240208-115529_Termux.png

@wherewhere wherewhere changed the title Help title How to construct a DeviceClient Feb 12, 2024
@itapi
Copy link
Author

itapi commented Feb 12, 2024

@wherewhere thanks mate!
I know that I can init a new adbclient,but I want to listen in the background for a incoming device connection and disconnection...and the device monitor classs provide me that function....how can I do it with adbclient?

@wherewhere
Copy link
Member

DeviceClient doesn't use IAdbClient. It use IAdbSocket to monitor device list changing. So you need to init an AdbClient by yourself. You can save one as a static property and use it when device list changed.

@itapi
Copy link
Author

itapi commented Feb 12, 2024

@wherewhere thanks sir!
Sorry to bother you,but can you please give me a code example for it?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants