Allow getting data through intent
Fix display not loading on create
This commit is contained in:
parent
7325e43efb
commit
ce6181b61d
2 changed files with 48 additions and 0 deletions
|
@ -19,6 +19,7 @@
|
||||||
android:theme="@style/Theme.SimpleBLEReceiver">
|
android:theme="@style/Theme.SimpleBLEReceiver">
|
||||||
<intent-filter>
|
<intent-filter>
|
||||||
<action android:name="android.intent.action.MAIN" />
|
<action android:name="android.intent.action.MAIN" />
|
||||||
|
<action android:name="systems.kumi.simplerfiddemo.NEW_TAG" />
|
||||||
|
|
||||||
<category android:name="android.intent.category.LAUNCHER" />
|
<category android:name="android.intent.category.LAUNCHER" />
|
||||||
</intent-filter>
|
</intent-filter>
|
||||||
|
|
|
@ -10,8 +10,10 @@ import android.bluetooth.le.ScanCallback
|
||||||
import android.bluetooth.le.ScanResult
|
import android.bluetooth.le.ScanResult
|
||||||
import android.Manifest
|
import android.Manifest
|
||||||
import android.annotation.SuppressLint
|
import android.annotation.SuppressLint
|
||||||
|
import android.content.BroadcastReceiver
|
||||||
import android.content.Context
|
import android.content.Context
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
|
import android.content.IntentFilter
|
||||||
import android.content.pm.PackageManager
|
import android.content.pm.PackageManager
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.os.ParcelUuid
|
import android.os.ParcelUuid
|
||||||
|
@ -63,6 +65,51 @@ class MainActivity : ComponentActivity() {
|
||||||
startActivityForResult(enableBtIntent, REQUEST_ENABLE_BT)
|
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() {
|
private fun startScanning() {
|
||||||
|
|
Loading…
Reference in a new issue