diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 376d069..0235b65 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -19,6 +19,7 @@ android:theme="@style/Theme.SimpleBLEReceiver"> + diff --git a/app/src/main/java/systems/kumi/simpleblereceiver/MainActivity.kt b/app/src/main/java/systems/kumi/simpleblereceiver/MainActivity.kt index 50ee76b..698eb6d 100644 --- a/app/src/main/java/systems/kumi/simpleblereceiver/MainActivity.kt +++ b/app/src/main/java/systems/kumi/simpleblereceiver/MainActivity.kt @@ -10,8 +10,10 @@ import android.bluetooth.le.ScanCallback import android.bluetooth.le.ScanResult import android.Manifest import android.annotation.SuppressLint +import android.content.BroadcastReceiver import android.content.Context import android.content.Intent +import android.content.IntentFilter import android.content.pm.PackageManager import android.os.Bundle import android.os.ParcelUuid @@ -63,6 +65,51 @@ class MainActivity : ComponentActivity() { startActivityForResult(enableBtIntent, REQUEST_ENABLE_BT) } + val intentFilter = IntentFilter("systems.kumi.simplerfiddemo.NEW_TAG") + registerReceiver(appReceiver, intentFilter) + + setContent { + SimpleBLEReceiverTheme { + Surface( + modifier = Modifier.fillMaxSize(), + color = MaterialTheme.colorScheme.background + ) { + Column { + Text("Waiting for data...") + + Button(onClick = { emitIntent("sample-id") }) { + Text("Emit sample intent") + } + } + } + } + } + } + + private val appReceiver = object : BroadcastReceiver() { + override fun onReceive(context: Context?, intent: Intent?) { + val data = intent?.getStringExtra("data") + if (data != null) { + runOnUiThread { + setContent { + SimpleBLEReceiverTheme { + Surface( + modifier = Modifier.fillMaxSize(), + color = MaterialTheme.colorScheme.background + ) { + Column { + Text("Received data: $data (from intent)") + + Button(onClick = { emitIntent("sample-id") }) { + Text("Emit sample data") + } + } + } + } + } + } + } + } } private fun startScanning() {