-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDroneSignalDetector.kt
More file actions
44 lines (38 loc) · 1.32 KB
/
DroneSignalDetector.kt
File metadata and controls
44 lines (38 loc) · 1.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package com.example.dronedetect
import android.content.BroadcastReceiver
import android.content.Context
import android.content.Intent
import android.net.wifi.WifiManager
import android.os.Handler
import android.os.Looper
import kotlinx.coroutines.CoroutineScope
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.SupervisorJob
import kotlinx.coroutines.cancel
import kotlinx.coroutines.launch
import kotlinx.coroutines.withContext
class DroneSignalDetector(private val context: Context) {
private val handler = Handler(Looper.getMainLooper())
private val wifiManager = context.applicationContext.getSystemService(Context.WIFI_SERVICE) as WifiManager
private val receiver = WifiScanReceiver()
private val scope = CoroutineScope(SupervisorJob() + Dispatchers.IO)
fun startScan() {
scope.launch {
fetchFlightData()
// TODO: implement scanning logic
}
}
suspend fun fetchFlightData() = withContext(Dispatchers.IO) {
// TODO: implement fetching flight data
}
fun stopScan() {
handler.removeCallbacksAndMessages(null)
context.unregisterReceiver(receiver)
scope.cancel()
}
}
class WifiScanReceiver : BroadcastReceiver() {
override fun onReceive(context: Context?, intent: Intent?) {
// TODO: handle scan results
}
}