update
This commit is contained in:
parent
6ca0e3d569
commit
76b4e4d8d8
5 changed files with 25 additions and 26 deletions
|
@ -3,20 +3,7 @@
|
||||||
<component name="deploymentTargetDropDown">
|
<component name="deploymentTargetDropDown">
|
||||||
<value>
|
<value>
|
||||||
<entry key="app">
|
<entry key="app">
|
||||||
<State>
|
<State />
|
||||||
<targetSelectedWithDropDown>
|
|
||||||
<Target>
|
|
||||||
<type value="QUICK_BOOT_TARGET" />
|
|
||||||
<deviceKey>
|
|
||||||
<Key>
|
|
||||||
<type value="VIRTUAL_DEVICE_PATH" />
|
|
||||||
<value value="$USER_HOME$/.android/avd/Pixel_3a_API_34_extension_level_7_x86_64.avd" />
|
|
||||||
</Key>
|
|
||||||
</deviceKey>
|
|
||||||
</Target>
|
|
||||||
</targetSelectedWithDropDown>
|
|
||||||
<timeTargetWasSelectedWithDropDown value="2024-05-18T10:28:26.053108340Z" />
|
|
||||||
</State>
|
|
||||||
</entry>
|
</entry>
|
||||||
</value>
|
</value>
|
||||||
</component>
|
</component>
|
||||||
|
|
|
@ -37,9 +37,10 @@ import eu.m724.bt.ui.theme.PicoBtAndroidTheme
|
||||||
class MainActivity : ComponentActivity() {
|
class MainActivity : ComponentActivity() {
|
||||||
private val requestPermission =
|
private val requestPermission =
|
||||||
registerForActivityResult(
|
registerForActivityResult(
|
||||||
ActivityResultContracts.RequestPermission()
|
ActivityResultContracts.RequestMultiplePermissions()
|
||||||
) { granted ->
|
) { granted ->
|
||||||
onPermissionGranted(granted)
|
val all = granted.values.all { all -> all }
|
||||||
|
onPermissionGranted(all)
|
||||||
}
|
}
|
||||||
|
|
||||||
private val btEnableActivityResult =
|
private val btEnableActivityResult =
|
||||||
|
@ -54,18 +55,19 @@ class MainActivity : ComponentActivity() {
|
||||||
).show()
|
).show()
|
||||||
finishAffinity()
|
finishAffinity()
|
||||||
}
|
}
|
||||||
|
bluetoothHelper.start()
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
private val deviceList = mutableStateListOf("a", "b", "c")
|
private val deviceList = mutableStateListOf("a", "b", "c")
|
||||||
|
|
||||||
private fun bluetoothPermission() {
|
private fun bluetoothPermission() {
|
||||||
if (checkSelfPermission(
|
requestPermission.launch(
|
||||||
Manifest.permission.BLUETOOTH_CONNECT
|
arrayOf(
|
||||||
) != PackageManager.PERMISSION_GRANTED
|
Manifest.permission.BLUETOOTH_CONNECT,
|
||||||
) {
|
Manifest.permission.BLUETOOTH_SCAN
|
||||||
requestPermission.launch(Manifest.permission.BLUETOOTH_CONNECT)
|
)
|
||||||
} else onPermissionGranted(true)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
private lateinit var bluetoothHelper: BluetoothHelper
|
private lateinit var bluetoothHelper: BluetoothHelper
|
||||||
|
|
|
@ -14,19 +14,24 @@ import androidx.core.app.ActivityCompat
|
||||||
import kotlinx.coroutines.CoroutineScope
|
import kotlinx.coroutines.CoroutineScope
|
||||||
import kotlinx.coroutines.Dispatchers
|
import kotlinx.coroutines.Dispatchers
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
|
import java.util.logging.Handler
|
||||||
|
|
||||||
class BluetoothHelper(
|
class BluetoothHelper(
|
||||||
val context: Context,
|
val context: Context,
|
||||||
val deviceList: SnapshotStateList<String>
|
val deviceList: SnapshotStateList<String>
|
||||||
) {
|
) {
|
||||||
|
private var started: Boolean = false
|
||||||
private val bluetoothManager: BluetoothManager =
|
private val bluetoothManager: BluetoothManager =
|
||||||
context.getSystemService(Context.BLUETOOTH_SERVICE) as BluetoothManager
|
context.getSystemService(Context.BLUETOOTH_SERVICE) as BluetoothManager
|
||||||
private val bluetoothAdapter: BluetoothAdapter =
|
private val bluetoothAdapter: BluetoothAdapter =
|
||||||
bluetoothManager.adapter
|
bluetoothManager.adapter
|
||||||
private lateinit var bluetoothLeScanner: BluetoothLeScanner
|
private lateinit var bluetoothLeScanner: BluetoothLeScanner
|
||||||
|
|
||||||
@Throws(SecurityException::class)
|
@SuppressLint("MissingPermission")
|
||||||
fun init(): Int {
|
fun start(): Int {
|
||||||
|
if (started) return 0
|
||||||
|
started = true
|
||||||
|
|
||||||
bluetoothLeScanner = bluetoothAdapter.bluetoothLeScanner
|
bluetoothLeScanner = bluetoothAdapter.bluetoothLeScanner
|
||||||
|
|
||||||
if (!bluetoothAdapter.isEnabled)
|
if (!bluetoothAdapter.isEnabled)
|
||||||
|
@ -34,6 +39,9 @@ class BluetoothHelper(
|
||||||
|
|
||||||
bluetoothLeScanner.startScan(scanCallback)
|
bluetoothLeScanner.startScan(scanCallback)
|
||||||
System.out.println("scanning now")
|
System.out.println("scanning now")
|
||||||
|
android.os.Handler().postDelayed(Runnable {
|
||||||
|
bluetoothLeScanner.stopScan(scanCallback)
|
||||||
|
}, 10000)
|
||||||
return 0
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -52,11 +60,13 @@ class BluetoothHelper(
|
||||||
private val scanCallback: ScanCallback =
|
private val scanCallback: ScanCallback =
|
||||||
object : ScanCallback() {
|
object : ScanCallback() {
|
||||||
override fun onScanResult(callbackType: Int, result: ScanResult) {
|
override fun onScanResult(callbackType: Int, result: ScanResult) {
|
||||||
|
super.onScanResult(callbackType, result)
|
||||||
addDevice(result)
|
addDevice(result)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onScanFailed(errorCode: Int) {
|
override fun onScanFailed(errorCode: Int) {
|
||||||
super.onScanFailed(errorCode)
|
super.onScanFailed(errorCode)
|
||||||
|
println("scam failed :((( $errorCode")
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onBatchScanResults(results: MutableList<ScanResult>?) {
|
override fun onBatchScanResults(results: MutableList<ScanResult>?) {
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
[versions]
|
[versions]
|
||||||
agp = "8.3.1"
|
agp = "8.4.0"
|
||||||
kotlin = "1.9.0"
|
kotlin = "1.9.0"
|
||||||
coreKtx = "1.12.0"
|
coreKtx = "1.12.0"
|
||||||
junit = "4.13.2"
|
junit = "4.13.2"
|
||||||
|
|
2
gradle/wrapper/gradle-wrapper.properties
vendored
2
gradle/wrapper/gradle-wrapper.properties
vendored
|
@ -1,6 +1,6 @@
|
||||||
#Thu May 16 18:07:40 CEST 2024
|
#Thu May 16 18:07:40 CEST 2024
|
||||||
distributionBase=GRADLE_USER_HOME
|
distributionBase=GRADLE_USER_HOME
|
||||||
distributionPath=wrapper/dists
|
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
|
zipStoreBase=GRADLE_USER_HOME
|
||||||
zipStorePath=wrapper/dists
|
zipStorePath=wrapper/dists
|
||||||
|
|
Loading…
Reference in a new issue