Skip to content

Commit

Permalink
Add example documentation for Bluetooth implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
sabzo committed Feb 15, 2018
1 parent 9e41a7f commit 9248921
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 1 deletion.
49 changes: 49 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,55 @@ a = new Ayanda(this, null, null, new IWifiDirect() {

a.wdDiscover();
```
Sharing a file (bytes) using Bluetooth
```java
a = new Ayanda(this, new IBluetooth() {
@Override
public void actionDiscoveryStarted(Intent intent) {}

@Override
public void actionDiscoveryFinished(Intent intent) {}

@Override
public void stateChanged(Intent intent) {}

@Override
public void scanModeChange(Intent intent) {}

@Override
public void actionFound(Intent intent) {
peersAdapter.clear();
peersAdapter.addAll(a.btGetDeviceNamesDiscovered());
devices = a.btGetDevices();
}

@Override
public void dataRead(byte[] bytes, int length) {
String readMessage = new String(bytes, 0, length);
Toast.makeText(BluetoothActivity.this, readMessage, Toast.LENGTH_LONG)
.show();
}

// Send "Hello World" after connecting to a device
@Override
public void connected(BluetoothDevice device) {
String message = "Hello World";
try {
a.btSendData(device, message.getBytes()); // maybe a class for a device that's connected
} catch (IOException e) {
e.printStackTrace();
}
}
}, null, null);
// Discover nearby Bluetooth devices paired or not
a.btDiscover();
// Connect to device from list
@Override
public void onItemClick(AdapterView<?> adapterView, View view, int pos, long l) {
BluetoothDevice device = devices.get(peerNames.get(pos));
a.btConnect(device); // will trigger "connected" event
}
```
See Example App in the app folder for more implementation details.


Expand Down
2 changes: 1 addition & 1 deletion app/src/main/java/sample/BluetoothActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ public void onClick(View view) {
@Override
public void onItemClick(AdapterView<?> adapterView, View view, int pos, long l) {
BluetoothDevice device = devices.get(peerNames.get(pos));
a.btConnect(device);
a.btConnect(device);
}
};

Expand Down

0 comments on commit 9248921

Please sign in to comment.