Forum Xamarin.Android

BLE will not scan

blearibleari Member ✭✭
edited August 2018 in Xamarin.Android

Previously, I added code using the plugin Bluetooth LE plugin for Xamari to scan for ble devices. It had worked for a while but I have since updated to the latest version of Xamarin and Visual Studio, now it just returns with 0 devices in the list. I am compiling using android version 8.1. Is there an issue with my code or an update issue?

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;


            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;
            ble.StateChanged += (s, e) =>
            adapter.DeviceDiscovered += (s, a) => deviceList.Add(a.Device);
            await adapter.StartScanningForDevicesAsync();

Best Answers

  • blearibleari Member ✭✭
    Accepted Answer

    @EricHamrick Thanks for the help


  • AlessandroCaliaroAlessandroCaliaro ITMember ✭✭✭✭✭
    I think you should open an issue on GitHub
  • EricHamrickEricHamrick USMember ✭✭

    Make sure you give your app Location permission explicitly in any Android version from 6 onwards. If you don't you won't receive any results on a scan. Its not good enough to just put the permission in the manifest.

  • blearibleari Member ✭✭

    @EricHamrick Thanks for the reply. Where else do I need to put it, its already in the manifest?

  • blearibleari Member ✭✭
    Accepted Answer

    @EricHamrick Thanks for the help

Sign In or Register to comment.