File tree Expand file tree Collapse file tree
app/src/main/java/com/example/dronedetect Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -6,19 +6,34 @@ import android.content.Intent
66import android.net.wifi.WifiManager
77import android.os.Handler
88import android.os.Looper
9+ import kotlinx.coroutines.CoroutineScope
10+ import kotlinx.coroutines.Dispatchers
11+ import kotlinx.coroutines.SupervisorJob
12+ import kotlinx.coroutines.cancel
13+ import kotlinx.coroutines.launch
14+ import kotlinx.coroutines.withContext
915
1016class DroneSignalDetector (private val context : Context ) {
1117 private val handler = Handler (Looper .getMainLooper())
1218 private val wifiManager = context.applicationContext.getSystemService(Context .WIFI_SERVICE ) as WifiManager
1319 private val receiver = WifiScanReceiver ()
20+ private val scope = CoroutineScope (SupervisorJob () + Dispatchers .IO )
1421
1522 fun startScan () {
16- // TODO: implement scanning logic
23+ scope.launch {
24+ fetchFlightData()
25+ // TODO: implement scanning logic
26+ }
27+ }
28+
29+ suspend fun fetchFlightData () = withContext(Dispatchers .IO ) {
30+ // TODO: implement fetching flight data
1731 }
1832
1933 fun stopScan () {
2034 handler.removeCallbacksAndMessages(null )
2135 context.unregisterReceiver(receiver)
36+ scope.cancel()
2237 }
2338}
2439
You can’t perform that action at this time.
0 commit comments