pszklarska / beacon_broadcast

A Flutter plugin for turning your device into a beacon.
https://pub.dartlang.org/packages/beacon_broadcast/
MIT License
81 stars 33 forks source link

Could not broadcast on Android #3

Closed tamnguyen-kbtg closed 5 years ago

tamnguyen-kbtg commented 5 years ago

I used this lib to broadcast and used other libs to scan beacons. I tested on real devices:

I used another android app (install from PlayStore) to broadcast and my app can see that device. That means there is something wrong on the broadcast from my app.

BeaconBroadcast beaconBroadcast = BeaconBroadcast();

if (Platform.isIOS) {
      beaconBroadcast
        .setUUID('XXXX-...')
        .setMajorId(2)
        .setMinorId(102)
        .start();
    }else{
      beaconBroadcast
        .setUUID('XXXX-...')
        .setMajorId(5)
        .setMinorId(105)
        .start();
    }
pszklarska commented 5 years ago

Hi @tamnguyen-kbtg, thank you for the feedback 👍 To summarize, when you broadcast from iOS device, everything works, but when you broadcast from Android device, you don't see your device in the other app that scans for beacons?

tamnguyen-kbtg commented 5 years ago

yes, that's correct

pszklarska commented 5 years ago

Ok, can you please provide me model of the devices? Does it happen on one device, or have you tested this on more models? Can you please also paste logs after you've started broadcasting?

tamnguyen-kbtg commented 5 years ago

I tested on 2 android phones: ZTE v7 Lite (Android 6.0) and Asus X018D (Android 7.0).

I wrote more code to logs the status:

var transmissionSupportStatus = await beaconBroadcast.checkTransmissionSupported();
switch (transmissionSupportStatus) {
  case BeaconStatus.SUPPORTED:
    // You're good to go, you can advertise as a beacon
    print('SUPPORTED');
    break;
  case BeaconStatus.NOT_SUPPORTED_MIN_SDK:
    // Your Android system version is too low (min. is 21)
    print('NOT_SUPPORTED_MIN_SDK');
    break;
  case BeaconStatus.NOT_SUPPORTED_BLE:
    // Your device doesn't support BLE
    print('NOT_SUPPORTED_BLE');
    break;
  case BeaconStatus.NOT_SUPPORTED_CANNOT_GET_ADVERTISER:
    // Either your chipset or driver is incompatible
    print('NOT_SUPPORTED_CANNOT_GET_ADVERTISER');
    break;
}

Logs:

Launching lib/main_dev.dart on ASUS X018D in debug mode...
Initializing gradle...
Resolving dependencies...
Running Gradle task 'assembleDebug'...
Built build/app/outputs/apk/debug/app-debug.apk.
Installing build/app/outputs/apk/app.apk...
D/BluetoothAdapter(22456): getLeState() returning 12
D/BluetoothAdapter(22456): 63499418: getState(). Returning 12
D/BeaconParser(22456): Parsing beacon layout: m:2-3=beac,i:4-19,i:20-21,i:22-23,p:24-24,d:25-25
D/BluetoothAdapter(22456): getLeState() returning 12
D/BluetoothAdapter(22456): 63499418: getState(). Returning 12
D/BluetoothLeAdvertiser(22456): startAdvertising
D/BluetoothAdapter(22456): getLeState() returning 12
D/BluetoothAdapter(22456): STATE_ON
D/BluetoothAdapter(22456): 63499418: getState(). Returning 12
D/BluetoothLeAdvertiser(22456): onClientRegistered() - status=0 clientIf=10
Syncing files to device ASUS X018D...
I/BeaconTransmitter(22456): Advertisement start succeeded.
D/BluetoothAdapter(22456): getLeState() returning 12
D/BluetoothAdapter(22456): 63499418: getState(). Returning 12
I/flutter (22456): SUPPORTED
D/GraphicBuffer(22456): register, handle(0x74c952d180) (w:720 h:1336 s:720 f:0x1 u:0x000b00)
pszklarska commented 5 years ago

@tamnguyen-kbtg from the logs it looks like BLE on Android is fine. Can you make one more test and run the code from the example?

beaconBroadcast
    .setUUID('39ED98FF-2900-441A-802F-9C398FC199D2')
    .setMajorId(1)
    .setMinorId(100)
    .start();
tamnguyen-kbtg commented 5 years ago

Hi @pszklarska,

After research and do some testing, I found the root cause is related to beacon type. iOS is only compatible with iBeacon, so I need to set Layout to iBeacon (default is AltBeacon). The second change is the Manufacturer Id. I set it to Apple value (0x004c). That is a couple of things we need to do if we want to work on both android and ios.

Thanks for your help.

In the near future, I'm going to keep broadcasting while app in background mode. Do you have any plan to do it? Please give me some advice if you have any idea.

pszklarska commented 5 years ago

Hi @tamnguyen-kbtg, it's great to hear it. I'll check it and if it turns out to be ok, I'll post this info on library page.

According to the background mode, it's currently hard to implement on the library's side due to iOS limitations (see Advertise Your Beacon Over Bluetooth section), but you may achieve it using Flutter Isloates.

Since it looks like a resolved issue, I'm closing this :)