There is no need for (actually no use of using) Xamarin for this task. All you'll need is the Android Debug Bridge (ADB) (see the linked page for instructions on how to install it)
To enable and disable the mobile data connection, use the commands
adb shell svc data enable
adb shell svc data disable
(see this answer, I've not marked this question as duplicate because it is scoped a bit differently)
Please note that USB debugging has to be enabled on the device.
In your windows application, you can implement the following class to en- or disable mobile data.
class MobileDeviceService
{
public void DisableMobileData()
{
Process.Start("adb.exe", "shell svc data disable");
}
public void EnableMobileData()
{
Process.Start("adb.exe", "shell svc data enable");
}
}
If you'd like to hide the window or block until the command has finished, you can use Process.Start(ProcessStartInfo)
with a StartInfo
instance (see the docs for ProcessStartInfo
) that has been configured respectively.
If there is more than one device attached to your PC, you can list the connected devices with
adb devices
and then use the -s <SERIAL>
option, to select the respective device
public void EnableMobileData(string deviceSerial)
{
Process.Start("adb.exe", $"-s {deviceSerial} shell svc data enable");
}