DanTheMan827.OnDeviceADB 3.0.0

dotnet add package DanTheMan827.OnDeviceADB --version 3.0.0
                    
NuGet\Install-Package DanTheMan827.OnDeviceADB -Version 3.0.0
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="DanTheMan827.OnDeviceADB" Version="3.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="DanTheMan827.OnDeviceADB" Version="3.0.0" />
                    
Directory.Packages.props
<PackageReference Include="DanTheMan827.OnDeviceADB" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add DanTheMan827.OnDeviceADB --version 3.0.0
                    
#r "nuget: DanTheMan827.OnDeviceADB, 3.0.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#addin nuget:?package=DanTheMan827.OnDeviceADB&version=3.0.0
                    
Install DanTheMan827.OnDeviceADB as a Cake Addin
#tool nuget:?package=DanTheMan827.OnDeviceADB&version=3.0.0
                    
Install DanTheMan827.OnDeviceADB as a Cake Tool

OnDeviceADB

A C# project containing ADB built for Android and a helper class to control it.

Sample

namespace DanTheMan827.OnDeviceADB
{
    /// <summary>
    /// Represents a sample class for interacting with ADB (Android Debug Bridge).
    /// </summary>
    public class AdbSample
    {
        /// <summary>
        /// Indicates whether the instance has been initialized.
        /// </summary>
        private bool _hasInitialized = false;

        /// <summary>
        /// Initializes a new instance of the <see cref="AdbSample"/> class.
        /// </summary>
        public AdbSample() { }

        /// <summary>
        /// Initializes the ADB sample asynchronously.  This should only be run once.
        /// </summary>
        /// <returns>A task representing the asynchronous operation.</returns>
        public async Task<AdbSample> Initialize()
        {
            if (!_hasInitialized)
            {
                _hasInitialized = true;

                // Kill any existing ADB server instance.
                await AdbWrapper.KillServerAsync();

                // Start a new ADB server instance.
                await AdbWrapper.StartServerAsync();

                // Get the list of connected devices.
                var devices = await AdbWrapper.GetDevicesAsync();

                // If no devices are connected, enable ADB over WiFi.
                if (devices.Length == 0)
                {
                    // Store the current wireless debugging state.
                    var adbWifiState = AdbWrapper.AdbWifiState;

                    // Enable wireless debugging while cycling it to ensure we go from a disabled state to enabled.
                    var port = await AdbWrapper.EnableAdbWiFiAsync(true);

                    // If the port is above 0 we were successful.
                    if (port > 0)
                    {
                        // Connect to the loopback IP on the detected port.
                        var device = await AdbWrapper.ConnectAsync("127.0.0.1", port);

                        // Switch to tcpip mode.
                        await AdbWrapper.TcpIpMode(device);

                        // Kill the server to ensure it refreshes.
                        await AdbWrapper.KillServerAsync();

                        // Launch the server.
                        await AdbWrapper.StartServerAsync();
                    }

                    // Restore the saved wireless debugging state.
                    AdbWrapper.AdbWifiState = adbWifiState;
                }

                // Grant necessary permissions to all connected devices.
                await AdbWrapper.GrantPermissionsAsync();
            }

            // Return our own instance for chaining.
            return this;
        }

        /// <summary>
        /// Tests ADB by running a shell command asynchronously.
        /// </summary>
        /// <returns>A task representing the asynchronous operation, with the command output as a result.</returns>
        public async Task<string> TestAdb()
        {
            return (await AdbWrapper.RunShellCommand(null, "ls", "-lah", "/sdcard/")).Output;
        }
    }
}

License

Copyright 2024 Daniel Radtke

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Product Compatible and additional computed target framework versions.
.NET net8.0-android34.0 is compatible.  net9.0-android was computed.  net10.0-android was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • net8.0-android34.0

    • No dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
3.0.0 269 3/23/2025
2.0.0 214 6/15/2024
1.0.0 156 6/6/2024