Skip to content

Commit

Permalink
Update the code samples
Browse files Browse the repository at this point in the history
  • Loading branch information
qmfrederik committed Aug 24, 2017
1 parent eb2c557 commit 7b6f854
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ SharpAdbClient does not communicate directly with your Android devices, but uses
You can do so by either running `adb.exe` yourself (it comes as a part of the ADK, the Android Development Kit), or you can use the `AdbServer.StartServer` method like this:

```
AdbServer.StartServer(@"C:\Program Files (x86)\android-sdk\platform-tools\adb.exe", restartServerIfNewer: false);
AdbServer server = new AdbServer();
var result = server.StartServer(@"C:\Program Files (x86)\android-sdk\platform-tools\adb.exe", restartServerIfNewer: false);
```

### List all Android devices currently connected
Expand All @@ -50,7 +51,7 @@ To receive notifications when devices connect to or disconnect from your PC, you
```
void Test()
{
var monitor = new DeviceMonitor(new AdbSocket());
var monitor new DeviceMonitor(new AdbSocket(new IPEndPoint(IPAddress.Loopback, AdbClient.AdbServerPort)));
monitor.DeviceConnected += this.OnDeviceConnected;
monitor.Start();
}
Expand All @@ -74,28 +75,30 @@ void InstallApplication()
```

### Send or receive files
To send files to or receive files from your Android device, you can use the `SyncService` class like this:
To send files to or receive files from your Android device, you can use the `SyncService` class. When uploading a file, you need to specify
the permissions of the file. These are standard Unix file permissions. For example, `444` will give everyone read permissions and `666` will
give everyone write permissions. You also need to specify the date at which the file was last modified. A good default there is `DateTime.Now`.

```
void DownloadFile()
{
var device = AdbClient.Instance.GetDevices().First();
using (SyncService service = new SyncService(new AdbSocket(), device))
using (SyncService service = new SyncService(new AdbSocket(new IPEndPoint(IPAddress.Loopback, AdbClient.AdbServerPort)), device))
using (Stream stream = File.OpenWrite(@"C:\MyFile.txt"))
{
service.Pull("/data/MyFile.txt", stream, null, CancellationToken.None);
service.Pull("/data/local/tmp/MyFile.txt", stream, null, CancellationToken.None);
}
}
void UploadFile()
{
var device = AdbClient.Instance.GetDevices().First();
using (SyncService service = new SyncService(new AdbSocket(), device))
using (SyncService service = new SyncService(new AdbSocket(new IPEndPoint(IPAddress.Loopback, AdbClient.AdbServerPort)), device))
using (Stream stream = File.OpenRead(@"C:\MyFile.txt"))
{
service.Push(stream, "/data/MyFile.txt", null, CancellationToken.None);
service.Push(stream, "/data/local/tmp/MyFile.txt", 444, DateTime.Now, null, CancellationToken.None);
}
}
```
Expand Down

0 comments on commit 7b6f854

Please sign in to comment.