mannprerak2 / nearby_connections

Flutter plugin (android) for sharing bytes and files Offline, (Based on the android Nearby Connections API)
https://pub.dev/packages/nearby_connections
BSD 2-Clause "Simplified" License
93 stars 30 forks source link

enhancement request for headless operation #11

Closed mpiparo closed 4 years ago

mpiparo commented 4 years ago

Requesting to implement the plugin to work in a headless environment, unless there are restrictions I am not aware of. Currently invoking plugin from within a headless callback results in NullPointerException: Activity must not be null. thanks!!

mannprerak2 commented 4 years ago

I am not quite sure what you mean, but you can make modifications and I'll be happy to accept a PR if it's working

mpiparo commented 4 years ago

My intent is to have the nearby connections to continue to discover after app shut-down. I'm using the fetch_background plugin to initiate a headless task callback (which fires every 15 min after app is shutdown/detached) to execute the startDiscovery method of the plugin. However, being called from a headless function gives me a "NullPointerException: Activity must not be null" error from the plugin. I've researched a bit about plugins executing from a headless state, (https://medium.com/flutter/executing-dart-in-the-background-with-flutter-plugins-and-geofencing-2b3e40a1a124) - but I wasn't sure if there were any limitations within the API that would prevent the discovery from working within a headless state after app shutdown?

mannprerak2 commented 4 years ago

https://medium.com/@elye.project/android-nearby-connections-vs-messages-a2bdf6a59ff3#work-across-android-activities-or-in-background This article mentions that the nearby connections API does not work in the background, this is a design choice made by google perhaps for security reasons.

For your purposes, this plugin may be helpful - https://pub.dev/packages/flutter_beacon