public override void OnReceive(Context context, Intent intent) { // Try to stop scan in a different "try\e" try { //https://stackoverflow.com/questions/4499915/how-to-stop-wifi-scan-on-android context.UnregisterReceiver(this); //InvokeAbortBroadcast not here: // https://medium.com/@ssaurel/develop-a-wifi-scanner-android-application-daa3b77feb73 //InvokeAbortBroadcast(); } catch (Exception ex) { AndroidLevelLogger.e(TAG, ex); } GetLatestWifiScanResults(intent.GetBooleanExtra(WifiManager.ExtraResultsUpdated, false)); AndroidLevelLogger.d(TAG, "Wifi scan result sucess"); }
public override IBinder OnBind(Intent intent) { AndroidLevelLogger.d(TAG, "OnBind"); return(null); }
public void setupAndroidBridge() { Context global_ctx = Application.Context; AndroidBridge._log_d = new Action <string, string>((tag, msg) => { AndroidLevelLogger.d(tag, msg); }); AndroidBridge._log_e = new Action <string, string>((tag, msg) => { AndroidLevelLogger.e(tag, msg); }); AndroidBridge._toast = new Action <string>((msg) => { try { AndroidUtils.ToastIt(global_ctx, msg); } catch (Exception ex) { Log.Error(AndroidBridge.TAG, ex.ToString()); } }); AndroidBridge._toast_from_back = new Action <string>((msg) => { try { AndroidUtils.ToastItFromBack(global_ctx, msg); } catch (Exception ex) { Log.Error(AndroidBridge.TAG, ex.ToString()); } }); AndroidBridge._readAsset = new Func <string, string, string>((tag, asset_name) => { string result = ""; try { result = FileHelpers.ReadAssetAsString(global_ctx, tag, asset_name); } catch (Exception ex) { Log.Error(AndroidBridge.TAG, ex.ToString()); } return(result); }); AndroidBridge._get_absolute_path = new Func <string, bool, string>((relative, isPulic) => { string result = ""; try { if (isPulic) { result = FileHelpers.getPublicAppFilePath(global_ctx, relative); } else { result = FileHelpers.getInternalAppFilePath(global_ctx, relative); } } catch (Exception ex) { Log.Error(AndroidBridge.TAG, ex.ToString()); } return(result); }); WifiScan.InitWifiScan(global_ctx); AndroidBridge._start_wifi_scan = new Action(() => { WifiScan.StartScanning(global_ctx); }); AndroidBridge._get_wifi_now = new Action(() => { WifiScan.WifiReceiver.GetLatestWifiScanResults(); }); AndroidBridge._start_service = new Action(() => { MyForegroundService.StartForegroundServiceCompat <MyForegroundService>(global_ctx, MyForegroundService.ACTION_START_SERVICE); }); AndroidBridge._stop_service = new Action(() => { MyForegroundService.StartForegroundServiceCompat <MyForegroundService>(global_ctx, MyForegroundService.ACTION_STOP_SERVICE); }); AndroidBridge._is_service_up = new Func <bool>(() => { return(MyForegroundService.IsServiceUp()); }); AndroidBridge._stop_all_jobs = () => { PeriodicTask.cancelAllJobs(global_ctx); }; AndroidBridge._stop_job = (int id) => { PeriodicTask.cancelJobById(global_ctx, id); }; AndroidBridge._schedule_job = new Func < TimeSpan?, TimeSpan?, TimeSpan?, Action <Action <bool> >, Func <bool>, Action, Func <bool>, int>( (latency, maxLatency, interval, _onJob, _shouldContinue, _onJobRequirementAbort, _shouldRetryAfterAbort) => { PeriodicTask.JobCallbacks job = new PeriodicTask.JobCallbacks() { onJob = _onJob, shouldContinue = _shouldContinue, onJobRequirementAbort = _onJobRequirementAbort, shouldRetryAfterAbort = _shouldRetryAfterAbort }; if (PeriodicTask.scheduleJob(global_ctx, job, latency, maxLatency, interval)) { return(job.JobUniqueID); } return(-1); } ); }