edufolly / flutter_bluetooth_serial

A basic Flutter Bluetooth Serial
MIT License
479 stars 464 forks source link

Discovery not working with sdk version 29 on certain devices #98

Open NailAgliev opened 4 years ago

NailAgliev commented 4 years ago

Problem summary

Call of startDiscovery() just produce those lines and nothing else.

D/FlutterBluePlugin(21036): Starting discovery
D/BluetoothAdapter(21036): startDiscovery

With SDK version 28 works as expected.

The issue found during testing on Samsung Galaxy S10 plus SM G975U1. Android version: 10. On Galaxy Tab A SM-T515. Android version: 9 everything works with SDK version 29.

Not sure it's only because of Android version difference or something else.

Steps to reproduce

import 'package:flutter/material.dart';
import 'package:flutter_bluetooth_serial/flutter_bluetooth_serial.dart';

void main() async {
  WidgetsFlutterBinding.ensureInitialized();

  FlutterBluetoothSerial.instance.startDiscovery().listen((result) {
    print(result.device.address);
  });
}
AgainPsychoX commented 4 years ago

If your app targets Android 10 or higher, it must have the ACCESS_FINE_LOCATION permission in order to use several methods within the Wi-Fi, Wi-Fi Aware, or Bluetooth APIs.

https://developer.android.com/about/versions/10/privacy/changes

Maybe adding the ACCESS_FINE_LOCATION permission will help it work on SDK 29?

I don't have how to test it myself.

magnuswikhog commented 3 years ago

This pull request seems to fix the issue of not working on Android 10, https://github.com/edufolly/flutter_bluetooth_serial/pull/110

Hopefully the authors will merge the pull request one day... until then, I guess we have to clone the plugin repo and make necessary changes ourselves, which is a shame on an otherwise very useful plugin.

FPT-HaiNV23 commented 3 years ago

Add ACCESS_FINE_LOCATION permission worked for me

qilanjie commented 3 years ago

add ACCESS_BACKGROUND_LOCATION