Open lchinke opened 6 years ago
Well, finally i made it work x).
Firstly, this error is generated because region.initFrameworkValue() is not called anywhere through the startMonitoring() methods. After this, i was getting some errors due to the results expected, so i changed the logic a bit.
At Channels.kt, change the startMonitoring() method that containts
launch(UI)
{result.successs(beaconsClient.startMonitoring(request)) }`
to
var operation: BeaconsClient.Operation? = null operation = BeaconsClient.Operation(BeaconsClient.Operation.Kind.Monitoring, request.region, request.inBackground) { result ->} beaconsClient.addRequest(operation!!, request.permission) result.success(null)
At channels.dart, change startMonitoring() method return statement to: (returns nothing)
return;// _Codec.decodeResult(response);
After doing this, the new beacon is being monitored withouth any errors. But this doesn't here. This plugin separates the control of monitoring between the listener of Beacons.monitoring() event and Beacons.backgroundMonitoringEvents(). I think this is just usefull when u want to have different beacon monitoring depending on the inBackground attribute. But if u want to manage all beacons in the same listener (that listens the events when the app is in foreground and active) you must do one thing.
In SharedMonitor.kt you must set in attachForegroundNotifier() method:
this.foregroundNotifier = null
and then, in the detachForegroundNotifier() method, comment the line:
// check(this.foregroundNotifier == notifier)
Hope Helped SomeOne!
I'll make this a pull request because everytime I want to update my packages especially in other 3rd party packages, the beacon package gets updated.
Steps:
I'm not familiar with the kotlin syntax, so I'll have to test it out.
At channels.dart, change startMonitoring() method return statement to: (returns nothing)
return;// _Codec.decodeResult(response);
in startMonitoring() method, it returns a Future of BeaconResult, changing to void will return nothing, I don't know what will happen to the response variable because I haven't tested it yet with this plugin as of now I'm using FlutterBlue which also scans any bluetooth device. I want to integrate this with beacon to know the distance of the beacon.
U can't exactly know the distance of the beacon. There is field that seems to give this value but i have tested it and sometimes this value is not good. Trust in the rssi.
Thank you for contributing into this.
The hardware I am using supports distance, but it's not really accurate as it fluctuates every second. FlutterBlue does have RSSI. but it doesn't have distance. so I'll be depending on this package.
Just do PR if you fixed something. There are tutorials on how to do PR(depends on what project you are to.) some are strict with CI enabled.
When I try to use the method Beacons.startMonitoring withouth starting a .monitor listener or stream (but set the backgroundMonitoringEvents method), the app crashes with the following error.
I/flutter (30714): beacons: invoke beacons->startMonitoring {"region":{"identifier":"test","ids":["b65de587b6494010af5bb6a733fc8ddd"],"bluetoothAddress":null},"permission":"coarse","inBackground":true} D/beacons client(30714): start Monitoring (inBackground:true) for region: test I/zygote64(30714): Do partial code cache collection, code=118KB, data=70KB I/zygote64(30714): After code cache collection, code=118KB, data=70KB I/zygote64(30714): Increasing code cache capacity to 512KB E/AndroidRuntime(30714): FATAL EXCEPTION: main E/AndroidRuntime(30714): Process: com.anxaneta.motobeacon, PID: 30714 E/AndroidRuntime(30714): kotlin.KotlinNullPointerException E/AndroidRuntime(30714): at io.intheloup.beacons.data.RegionModel.getFrameworkValue(RegionModel.kt:17) E/AndroidRuntime(30714): at io.intheloup.beacons.logic.SharedMonitor.start(SharedMonitor.kt:58) E/AndroidRuntime(30714): at io.intheloup.beacons.logic.BeaconsClient.startRequest(BeaconsClient.kt:188) E/AndroidRuntime(30714): at io.intheloup.beacons.logic.BeaconsClient.startMonitoring(BeaconsClient.kt:146) E/AndroidRuntime(30714): at io.intheloup.beacons.channel.Channels$startMonitoring$1.doResume(Channels.kt:65) E/AndroidRuntime(30714): at kotlin.coroutines.experimental.jvm.internal.CoroutineImpl.resume(CoroutineImpl.kt:42) E/AndroidRuntime(30714): at kotlinx.coroutines.experimental.DispatchedTask$DefaultImpls.run(Dispatched.kt:161) E/AndroidRuntime(30714): at kotlinx.coroutines.experimental.DispatchedContinuation.run(Dispatched.kt:25) E/AndroidRuntime(30714): at android.os.Handler.handleCallback(Handler.java:790) E/AndroidRuntime(30714): at android.os.Handler.dispatchMessage(Handler.java:99) E/AndroidRuntime(30714): at android.os.Looper.loop(Looper.java:164) E/AndroidRuntime(30714): at android.app.ActivityThread.main(ActivityThread.java:6499) E/AndroidRuntime(30714): at java.lang.reflect.Method.invoke(Native Method) E/AndroidRuntime(30714): at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:440) E/AndroidRuntime(30714): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:807) I/Process (30714): Sending signal. PID: 30714 SIG: 9 Lost connection to device.