BLE does not scan
See original GitHub issueSteps to reproduce
-
Plugin has been added as suggested.
-
Visual studio and Xamarin.Forms are updated to the latest version.
-
Code attached below
using System;
using Android.App;
using Android.Content.PM;
using Android.Runtime;
using Android.Views;
using Android.Widget;
using Android.OS;
using Plugin.BLE;
using Plugin.BLE.Abstractions.Exceptions;
using System.Collections.Generic;
using Android.Bluetooth;
using Whale_Watch.Droid;
namespace Whale_Watch.Droid
{
[Activity(Label = "BLE_Test", Theme = "@style/MainTheme", MainLauncher = true, ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation)]
public class MainActivity : global::Xamarin.Forms.Platform.Android.FormsAppCompatActivity
{
protected async override void OnCreate(Bundle bundle)
{
TabLayoutResource = Resource.Layout.Tabbar;
ToolbarResource = Resource.Layout.Toolbar;
base.OnCreate(bundle);
global::Xamarin.Forms.Forms.Init(this, bundle);
LoadApplication(new App());
await scanAsync();
}
public async System.Threading.Tasks.Task scanAsync()
{
List<Plugin.BLE.Abstractions.Contracts.IDevice> deviceList = new List<Plugin.BLE.Abstractions.Contracts.IDevice>();
var ble = CrossBluetoothLE.Current;
var adapter = CrossBluetoothLE.Current.Adapter;
var state = ble.State;
adapter.ScanTimeout = 200000;
adapter.DeviceDiscovered += (s, a) => deviceList.Add(a.Device);
await adapter.StartScanningForDevicesAsync();
}
}
}
Expected behavior
It should scan for all nearby Bluetooth le devices.
Actual behavior
It will run the code and no errors are formed, however even though there are ble devices visible it does not return any or add them to the list. I am unsure if my code is at fault.
Crashlog
Does not crash or cause an exception
Configuration
Version of the Plugin: 1.3.0
Platform: Compiled using Android 8.1
Device: Moto E4 Plus, but will also occur on all other devices tested.
Issue Analytics
- State:
- Created 5 years ago
- Comments:15
Top Results From Across the Web
Android 10 not working with BLE Bluetooth scanning
I am working on BLE Bluetooth scanning is working on all devices except the Android 10. Android 10 is not working, anyone please...
Read more >BLE not scanning or showing an devices
The problem is that older apps that I had already downloaded onto my device using the same code from App Inventor still work...
Read more >BLE.scan() example not working
Hi, I am trying to get the BLE.scan() example from the docs working. It compiles and I can flash it to my argon...
Read more >BLE Issues In Android 7 And Above
To resolve this issue, you can set a filter with any unique identifier like CompanyId or ManufactureId of your BLE device. And it...
Read more >BLE Scan does not work on Android 12 when targetSDK is ...
Hello ! I've a problem with scanning method on Android 12 (SDK 31). Since the update, if i start a scan, he will...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Okay, so this is pretty frustrating. Apparently you have to enable Location services for this to work on newer OS versions. Turn on location and everythign works fine no matter the version or manifest!
Found this out from a stackoverflow article, but haven’t seen ANYTHING about it in the android or Xamarin docs… Hope this solves some more people’s issues as well! Maybe a note about this should be added to the readme here as well?
This still applies. Very frustrating. Android 12
With GPS turned on, devices are discovered. With GPS turned off, no devices are discovered.