locked
i need to create an app Bluetooth in xamarin forms? RRS feed

  • Question

  • User370476 posted

    I need to create an app in xamarin forms where I read bluetooth devices and link, is it necessary to make the native app or can it be in forms? try with the plugin.BLE but it tells me that the .NETFramework is 4.0 and needs 2.0!!! i help me please

    Wednesday, July 4, 2018 10:41 PM

Answers

  • User355640 posted

    Hi @AlexCorts94

    It is a warning, you can build successfully, you can continue to use it. If you build fail with it, you can open a thread to ask what errors are you facing. Welcome to ask question.

    • Marked as answer by Anonymous Thursday, June 3, 2021 12:00 AM
    Thursday, July 12, 2018 9:41 AM

All replies

  • User368881 posted

    Everything you can do in a native project you can also do in Xamarin.Forms.

    Thursday, July 5, 2018 12:10 AM
  • User355640 posted

    Hi @AlexCorts94

    I can install the nuget, by but it tells me that the .NETFramework is 4.0 and needs 2.0 what do you mean? What error are you facing? Would you like share logs with us?

    Thursday, July 5, 2018 2:26 AM
  • User370476 posted

    @WasserEsser When I do my native app if the plugin.BLE and Mvvm work well.

    Hi @robbit This is the error.

    Package 'Plugin.BLE 1.3.0' was restored using '.NETFramework,Version=v4.6.1' instead of the project target framework '.NETStandard,Version=v2.0'. This package may not be fully compatible with your project. (NU1701) (BlueSIS)

    Wednesday, July 11, 2018 6:22 PM
  • User355640 posted

    Hi @AlexCorts94

    It is a warning, you can build successfully, you can continue to use it. If you build fail with it, you can open a thread to ask what errors are you facing. Welcome to ask question.

    • Marked as answer by Anonymous Thursday, June 3, 2021 12:00 AM
    Thursday, July 12, 2018 9:41 AM
  • User370476 posted

    Thanks u @robbit but when I try the app on the cell phone, the bluetooth scan buttons do not work. and if it compiles and executes well. This my code!!! also install nugets and plugins(MvvmCross, Plugin,BLE)

    using System; using System.Collections.ObjectModel; using Plugin.BLE; using Plugin.BLE.Abstractions.Contracts; using Plugin.BLE.Abstractions.Exceptions; using Xamarin.Forms;

    namespace DemoBluetooth { public partial class MainPage { IAdapter adapter; IBluetoothLE bluetoothBLE; ObservableCollection list; IDevice device;

        public MainPage()
        {
            InitializeComponent();
    
            bluetoothBLE = CrossBluetoothLE.Current;
            adapter = CrossBluetoothLE.Current.Adapter;
    
            list = new ObservableCollection<IDevice>();
            DevicesList.ItemsSource = list;
    
        }        
    
        private async void searchDevice(object sender, EventArgs e)
        {
            if (bluetoothBLE.State == BluetoothState.Off)
            {
                await DisplayAlert("Atenção", "Bluetooth desabilitado.", "OK");
            }
            else
            {
                list.Clear();
    
                adapter.ScanTimeout = 10000;
                adapter.ScanMode = ScanMode.Balanced;
    
    
                adapter.DeviceDiscovered += (obj, a) =>
                {
                    if (!list.Contains(a.Device))
                        list.Add(a.Device);
                };
    
                await adapter.StartScanningForDevicesAsync();
    
            }
    
        }
    
        private async void DevicesList_OnItemSelected(object sender, SelectedItemChangedEventArgs e)
        {
            device = DevicesList.SelectedItem as IDevice;
    
            var result = await DisplayAlert("AVISO", "Deseja se conectar a esse dispositivo?", "Conectar", "Cancelar");
    
            if (!result)
                return;
    
            //Stop Scanner
            await adapter.StopScanningForDevicesAsync();
    
            try
            {
                await adapter.ConnectToDeviceAsync(device);
    
                await DisplayAlert("Conectado", "Status:" + device.State , "OK");
    
            }
            catch (DeviceConnectionException ex)
            {
                await DisplayAlert("Erro", ex.Message, "OK");
            }
    
        }
    }
    

    }

    Thursday, July 12, 2018 10:27 PM
  • User382815 posted

    Hi @AlexCorts94, were you every able to get this resolved? Was it a permissions issue?

    Saturday, February 23, 2019 11:14 PM
  • User387074 posted

    @AlexCorts94 Can you solve the problem?

    Wednesday, July 3, 2019 1:30 PM