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