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

Unable to range and broadcast on Samsung Android 12 #131

Open
wieger opened this issue Jun 2, 2023 · 7 comments
Open

Unable to range and broadcast on Samsung Android 12 #131

wieger opened this issue Jun 2, 2023 · 7 comments

Comments

@wieger
Copy link

wieger commented Jun 2, 2023

Hi, I have build an app to scan for beacons using this package. It all works flawlessly on iOS devices but I cannot get it to work on my Android device, a samsung S10 running android 12.
I hope that someone which has managed to get it working can help me debug it, or point me towards a step I missed during the setup.
To debug it I am now running the example code provided in the repository
At first I was missing the proper permissions but I think I have that sorted, combining some previous posts on this forum.

I have the following permissions in main/AndroidManifest.xml

   <uses-permission android:name="android.permission.INTERNET" />
    <!--Before Android 12 (but still needed location, even if not requested)-->
    <uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />

    <uses-permission android:name="android.permission.BLUETOOTH" tools:remove="android:maxSdkVersion" />
    <uses-permission android:name="android.permission.BLUETOOTH_ADMIN" android:maxSdkVersion="30" />

    <uses-permission android:name="android.permission.BLUETOOTH_SCAN" android:usesPermissionFlags="neverForLocation" />
    <uses-permission android:name="android.permission.BLUETOOTH_CONNECT" />
    <uses-permission android:name="android.permission.BLUETOOTH_ADVERTISE" />

I request the required permissions with the following code, and all statuses resolve to granted

import 'package:permission_handler/permission_handler.dart';  //permission_handler: ^10.2.0

    PermissionStatus scan = await Permission.bluetoothScan.request();
    PermissionStatus connect = await Permission.bluetoothConnect.request();
    PermissionStatus bt = await Permission.bluetooth.request();
    PermissionStatus advertise = await Permission.bluetoothAdvertise.request();

I listen for beacons using: _streamRanging = flutterBeacon.ranging(regions).listen((RangingResult result) { print(result);

this does print a result but it contains no beacons:

I/flutter (27838): {"region":{"identifier":"BeaconType2","proximityUUID":"6a84c716-0f2a-1ce9-f210-6a63bd873dd9"},"beacons":[]}
I/flutter (27838): {"region":{"identifier":"Cubeacon","proximityUUID":"cb10023f-a318-3394-4199-a8730c7c1aec"},"beacons":[]}
I/flutter (27838): {"region":{"identifier":"MyRegion","proximityUUID":"xxxx-x-x-xxxx"},"beacons":[]}

Any help is greatly appreciated, thanks

@dalilabennasr
Copy link

@wieger did you find a solution?
I'm facing the same issue.
Thank you in advance

@wieger
Copy link
Author

wieger commented Jul 31, 2024 via email

@dalilabennasr
Copy link

@wieger do you remember what flutter sdk you were using?

@wieger
Copy link
Author

wieger commented Jul 31, 2024 via email

@dalilabennasr
Copy link

is the project in a git repo? is it public?

@wieger
Copy link
Author

wieger commented Jul 31, 2024 via email

@kjm0202
Copy link

kjm0202 commented Oct 14, 2024

Currently I'm using Galaxy S22 with One UI 4.1 (Android 12) for test and it works for now.
I think you might missed the request for location permission.
Here's what I'm using for permission acquirement, hope it works for you too:

import 'package:permission_handler/permission_handler.dart';
import 'package:device_info_plus/device_info_plus.dart';

Future<void> _requestPermissions() async {
    var androidInfo = await DeviceInfoPlugin().androidInfo;
    var androidSdk = androidInfo.version.sdkInt;

    final locationStatus = await Permission.location.request();
    if (locationStatus.isPermanentlyDenied) {
      openAppSettings();
    }

    if (androidSdk <= 30) {
      final bluetoothStatus = await Permission.bluetooth.request();
      if (bluetoothStatus.isPermanentlyDenied) {
        openAppSettings();
      }
      return;
    } else /* if (androidSdk > 30) */ {
      Map<Permission, PermissionStatus> statuses = await [
        Permission.bluetoothScan,
        Permission.bluetoothAdvertise,
        Permission.bluetoothConnect
      ].request();

      if (statuses[Permission.bluetoothScan] == PermissionStatus.denied ||
          statuses[Permission.bluetoothAdvertise] == PermissionStatus.denied ||
          statuses[Permission.bluetoothConnect] == PermissionStatus.denied) {
        openAppSettings();
      }
      return;
    }
  }

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

3 participants