Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

android bluetotth scaning not working,ios working #119

Open
iyashiyas opened this issue May 20, 2022 · 6 comments
Open

android bluetotth scaning not working,ios working #119

iyashiyas opened this issue May 20, 2022 · 6 comments

Comments

@iyashiyas
Copy link

iyashiyas commented May 20, 2022

Android Not scanning, ios working, is there. any option to scan paired devices ?

@ferns-it
Copy link

ferns-it commented Jun 8, 2022

Same issue, any solutions ??

@iyashiyas
Copy link
Author

solved the issue with adding permission from flutter also added android manifest.xml

var statusLocation = Permission.location;
var statusScan = Permission.bluetoothScan;
var statusConnect = Permission.bluetoothConnect;
if (Platform.isAndroid) {
if (await statusLocation.isDenied) {
await [
Permission.location,
].request();
}

    if (await statusLocation.isGranted &&
      await statusScan.isGranted &&
      await statusScan.isGranted) {
    commonPrint('all grnted');
    // do scan bluetooth device function
  }

@jobypthomas
Copy link

jobypthomas commented Sep 14, 2022

@iyashiyas @ferns-it can you share your AndroidManifest and a more detailed code snippet? Specifically have you used permission_handler package?

@jobypthomas
Copy link

@iyashiyas @ferns-it I was able to figure out. Thank you. However, it does not work with Android 12. Worked fine with Android 9.

@eliezedeck
Copy link

eliezedeck commented Sep 16, 2022

Android 12 doesn't work initially. You'll have to follow this: https://stackoverflow.com/questions/70578601/android-12-ble-scan-does-not-find-any-devices

As a result, I had these in the Android manifest file:

  <uses-permission android:name="android.permission.BLUETOOTH" />
  <uses-permission android:name="android.permission.BLUETOOTH_SCAN" />
  <uses-permission android:name="android.permission.BLUETOOTH_CONNECT" />
  <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
  <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />

Then I request the following permissions at runtime:

await Permission.bluetoothConnect.request();
await Permission.bluetoothScan.request();
await Permission.locationWhenInUse.request();

@ozhankucuk
Copy link

Thanks ,this works for me
I migrated my project to null safety.
targeting sdk 30 to 31

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants