-
Notifications
You must be signed in to change notification settings - Fork 32
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
onEndpointFound never gets called in dart code. Error : FlutterJNI(26633): Tried to send a platform message to Flutter, but FlutterJNI was detached from native C++. Could not send. Channel: nearby_connections. Response ID: 4 #75
Comments
Are you using this in a background service? This package is not built in a way to be used inside a background service, and I'm not sure if it's even possible to do so. |
No I am not using as background service. I am working on a expense manager app , and want to sync/send data over nearby communication. I am using bloc cubit. To be exact, on bloc cubit call, I start nearby Discover, on endpoint found, I request connection, once connection is approved onConnectionInitiated I stop discovery, then then try to send data separate isolate. but code never reaches upto isolate part. on on endpoint found callback never gets called and in console I get above error message. |
I have no experience of plugin/package development, but from stackoverflow As per first answer, root cause appears to be |
if it helps here is my cubit.sendDatamethod has below code
but execution never reaches logger line mentioned, it fails and gives above error. |
I'm guessing you cannot use a separate isolate, all the nearby connection interaction including any callbacks must be done in the main isolate itself. Try removing the isolate usage. |
but code doesn't even reach the isolate part. I will try commenting the actual business logic (that involves isolate) tomorrow and update here. Kindly check below stackoverflow thread once you get time. |
Method channel is not being cached. See Line 449 in 63104a9
I'm guessing you are somehow using an isolate to call the nearby connection function. If you are still not sure, you can post a link to a minimal reproducible sample I might be able to check it out over the weekend. |
Sorry looks like flutter version upgrade messed with gradle big time. |
I tried to simplify the code, and created a stateful widget like below. It never finds endpoints and gives below message in console
Here is the sample widget i have
|
Same issue.
Even when I use code from example in github
|
Is the example app behaving in a similar way? And is there any specific situation where this is happening? |
I tried to run example from Github directly, but for some reason it was failing to compile.
I used exact same code from example... just removed parts for permission checking buttons etc. as all required permission granted via I click on start advertising on one device and start discovering on 2nd device.
My devices are Both devices are connected to Same WIFI network. |
I do not have any experience in Flutter plugin development. I tried to debug a little by adding some logs to local version. onAttachedToEngine gets called when starting application
Just thought to post if it helps to resolve the issue. |
The issue here is - Once this method is called, there can no longer be any communication between java->dart. This is only untill What this means if the android activity goes in the background you wont get any updates. P.S i am unable to do any testing as of now, I can try maybe next week. |
I was going through below article to learn about plugin development. https://blog.stackademic.com/integrating-native-code-with-flutter-8fecca6db524 as per my understanding of the article there are 3 diff types of channels.
May be implementation needs to be changed to use either Basic Message Channel or combination of Method Channel & Event Channel. If its not related or incorrect feel free to neglect. |
Event Channel is used for streaming data like audio or video feed from device. Anyways, changing the channel wouldn't help. |
I tried on my local branch by combination of Method Channel & Event Channel. at least I was able to find the devices. request connection and accept the connection. |
Hi @rahulmaindargi, I've released a new version with your fix - Thank you for contributing 🚀 |
Below is the error when discovery finds a device. but onEndpointFound on dart side never gets called.
NearbyConnections(26633): NFC discovery started.
D/NearbyConnections(26633): Invalidating dispatch state.
D/NearbyConnections(26633): Starting NFC dispatching.
D/NearbyConnections(26633): Cannot dispatch NFC events. NFC is not supported.
D/nearby_connections(26633): startDiscovery
D/nearby_connections(26633): onEndpointFound
W/FlutterJNI(26633): Tried to send a platform message to Flutter, but FlutterJNI was detached from native C++. Could not send. Channel: nearby_connections. Response ID: 4
The text was updated successfully, but these errors were encountered: