diff --git a/.idea/deploymentTargetDropDown.xml b/.idea/deploymentTargetDropDown.xml
index a415442..0c0c338 100644
--- a/.idea/deploymentTargetDropDown.xml
+++ b/.idea/deploymentTargetDropDown.xml
@@ -3,20 +3,7 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+
diff --git a/app/src/main/java/eu/m724/bt/MainActivity.kt b/app/src/main/java/eu/m724/bt/MainActivity.kt
index 03ed95f..fa1c46b 100644
--- a/app/src/main/java/eu/m724/bt/MainActivity.kt
+++ b/app/src/main/java/eu/m724/bt/MainActivity.kt
@@ -37,9 +37,10 @@ import eu.m724.bt.ui.theme.PicoBtAndroidTheme
class MainActivity : ComponentActivity() {
private val requestPermission =
registerForActivityResult(
- ActivityResultContracts.RequestPermission()
+ ActivityResultContracts.RequestMultiplePermissions()
) { granted ->
- onPermissionGranted(granted)
+ val all = granted.values.all { all -> all }
+ onPermissionGranted(all)
}
private val btEnableActivityResult =
@@ -54,18 +55,19 @@ class MainActivity : ComponentActivity() {
).show()
finishAffinity()
}
+ bluetoothHelper.start()
}
)
private val deviceList = mutableStateListOf("a", "b", "c")
private fun bluetoothPermission() {
- if (checkSelfPermission(
- Manifest.permission.BLUETOOTH_CONNECT
- ) != PackageManager.PERMISSION_GRANTED
- ) {
- requestPermission.launch(Manifest.permission.BLUETOOTH_CONNECT)
- } else onPermissionGranted(true)
+ requestPermission.launch(
+ arrayOf(
+ Manifest.permission.BLUETOOTH_CONNECT,
+ Manifest.permission.BLUETOOTH_SCAN
+ )
+ )
}
private lateinit var bluetoothHelper: BluetoothHelper
diff --git a/app/src/main/java/eu/m724/bt/code/BluetoothHelper.kt b/app/src/main/java/eu/m724/bt/code/BluetoothHelper.kt
index 1ccc840..355c28c 100644
--- a/app/src/main/java/eu/m724/bt/code/BluetoothHelper.kt
+++ b/app/src/main/java/eu/m724/bt/code/BluetoothHelper.kt
@@ -14,19 +14,24 @@ import androidx.core.app.ActivityCompat
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
+import java.util.logging.Handler
class BluetoothHelper(
val context: Context,
val deviceList: SnapshotStateList
) {
+ private var started: Boolean = false
private val bluetoothManager: BluetoothManager =
context.getSystemService(Context.BLUETOOTH_SERVICE) as BluetoothManager
private val bluetoothAdapter: BluetoothAdapter =
bluetoothManager.adapter
private lateinit var bluetoothLeScanner: BluetoothLeScanner
- @Throws(SecurityException::class)
- fun init(): Int {
+ @SuppressLint("MissingPermission")
+ fun start(): Int {
+ if (started) return 0
+ started = true
+
bluetoothLeScanner = bluetoothAdapter.bluetoothLeScanner
if (!bluetoothAdapter.isEnabled)
@@ -34,6 +39,9 @@ class BluetoothHelper(
bluetoothLeScanner.startScan(scanCallback)
System.out.println("scanning now")
+ android.os.Handler().postDelayed(Runnable {
+ bluetoothLeScanner.stopScan(scanCallback)
+ }, 10000)
return 0
}
@@ -52,11 +60,13 @@ class BluetoothHelper(
private val scanCallback: ScanCallback =
object : ScanCallback() {
override fun onScanResult(callbackType: Int, result: ScanResult) {
+ super.onScanResult(callbackType, result)
addDevice(result)
}
override fun onScanFailed(errorCode: Int) {
super.onScanFailed(errorCode)
+ println("scam failed :((( $errorCode")
}
override fun onBatchScanResults(results: MutableList?) {
diff --git a/gradle/libs.versions.toml b/gradle/libs.versions.toml
index 82df186..e294170 100644
--- a/gradle/libs.versions.toml
+++ b/gradle/libs.versions.toml
@@ -1,5 +1,5 @@
[versions]
-agp = "8.3.1"
+agp = "8.4.0"
kotlin = "1.9.0"
coreKtx = "1.12.0"
junit = "4.13.2"
diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties
index 1869c4a..ecc154b 100644
--- a/gradle/wrapper/gradle-wrapper.properties
+++ b/gradle/wrapper/gradle-wrapper.properties
@@ -1,6 +1,6 @@
#Thu May 16 18:07:40 CEST 2024
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
-distributionUrl=https\://services.gradle.org/distributions/gradle-8.4-bin.zip
+distributionUrl=https\://services.gradle.org/distributions/gradle-8.6-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists