Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
weliem committed Jul 27, 2024
2 parents 470f5c4 + f9498bb commit 3951069
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 7 deletions.
28 changes: 27 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ The BLESSED library was inspired by CoreBluetooth on iOS and provides the same l

## Installation

This library is available on Jitpack. This library also uses Timber for logging. So include the following in your gradle file:
This library is available on Jitpack. This library also uses Timber for logging. So include the following in your gradle configuration:

```groovy
allprojects {
Expand All @@ -54,6 +54,32 @@ dependencies {
```
where `$version` is the latest published version in Jitpack [![](https://jitpack.io/v/weliem/blessed-kotlin.svg)](https://jitpack.io/#weliem/blessed-kotlin)

<details>

<summary>Kotlin DSL</summary>

settings.gradle.kts

```kotlin
dependencyResolutionManagement {
repositories {
...
maven { setUrl("https://jitpack.io") }
}
}
```

build.gradle.kts

```kotlin
dependencies {
implementation("com.github.weliem:blessed-kotlin:$version")
implementation("com.jakewharton.timber:timber:5.0.1")
}
```

</details>

## Scanning

The `BluetoothCentralManager` class has several differrent scanning methods:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ import java.util.concurrent.ConcurrentLinkedQueue
class BluetoothPeripheralManager(private val context: Context, private val bluetoothManager: BluetoothManager, private val callback: BluetoothPeripheralManagerCallback) {
private val mainHandler = Handler(Looper.getMainLooper())
private val bluetoothAdapter: BluetoothAdapter = bluetoothManager.adapter
private val bluetoothLeAdvertiser: BluetoothLeAdvertiser = bluetoothAdapter.bluetoothLeAdvertiser
private val bluetoothLeAdvertiser: BluetoothLeAdvertiser by lazy { bluetoothAdapter.bluetoothLeAdvertiser }
var isAdvertising: Boolean = false
private set

Expand Down
10 changes: 5 additions & 5 deletions peripheral/src/main/java/com/welie/btserver/MainActivity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,6 @@ class MainActivity : AppCompatActivity() {
}

private fun startAdvertising() {
if (!isBluetoothEnabled) {
enableBleRequest.launch(Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE))
return
}

val bluetoothServer = BluetoothServer.getInstance(applicationContext)
val peripheralManager = bluetoothServer.peripheralManager

Expand All @@ -40,6 +35,11 @@ class MainActivity : AppCompatActivity() {
return
}

if (!isBluetoothEnabled) {
enableBleRequest.launch(Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE))
return
}

// Make sure we initialize the server only once
if (!bluetoothServer.isInitialized) {
bluetoothServer.initialize()
Expand Down

0 comments on commit 3951069

Please sign in to comment.