Add button to emit test intent
This commit is contained in:
parent
71e9e228d3
commit
7325e43efb
1 changed files with 18 additions and 5 deletions
|
@ -19,6 +19,7 @@ import androidx.activity.ComponentActivity
|
|||
import androidx.activity.compose.setContent
|
||||
import androidx.compose.foundation.layout.Column
|
||||
import androidx.compose.foundation.layout.fillMaxSize
|
||||
import androidx.compose.material3.Button
|
||||
import androidx.compose.material3.MaterialTheme
|
||||
import androidx.compose.material3.Surface
|
||||
import androidx.compose.material3.Text
|
||||
|
@ -135,6 +136,12 @@ class MainActivity : ComponentActivity() {
|
|||
bluetoothGatt = device.connectGatt(this, false, gattCallback)
|
||||
}
|
||||
|
||||
private fun emitIntent(data: String) {
|
||||
val intent = Intent("systems.kumi.simpleblereceiver.DATA_RECEIVED")
|
||||
intent.putExtra("data", data)
|
||||
sendBroadcast(intent)
|
||||
}
|
||||
|
||||
private val gattCallback = object : BluetoothGattCallback() {
|
||||
@SuppressLint("MissingPermission")
|
||||
override fun onConnectionStateChange(gatt: BluetoothGatt?, status: Int, newState: Int) {
|
||||
|
@ -180,17 +187,19 @@ class MainActivity : ComponentActivity() {
|
|||
Column {
|
||||
Text("Connected to device: ${gatt?.device?.address}")
|
||||
Text("Received data: $dataString")
|
||||
|
||||
Button(onClick = { emitIntent("sample-id") }) {
|
||||
Text("Emit sample data")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Send out a broadcast with the received data
|
||||
// Assuming you have a broadcast receiver set up to handle this
|
||||
val intent = Intent("systems.kumi.simpleblereceiver.ACTION_DATA_RECEIVED")
|
||||
intent.putExtra("data", dataString)
|
||||
sendBroadcast(intent)
|
||||
if (dataString != null) {
|
||||
emitIntent(dataString)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -202,6 +211,10 @@ fun ReceiverStatus(deviceAddress: String? = null, data: String? = null) {
|
|||
Column {
|
||||
Text(text = "Device Address: ${deviceAddress ?: "Not connected"}")
|
||||
Text(text = "Data Received: ${data ?: "No data"}")
|
||||
|
||||
Button(onClick = {}) {
|
||||
Text(text = "Emit sample data")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue