Code Monkey home page Code Monkey logo

vnapnic / flutter_nearby_connections Goto Github PK

View Code? Open in Web Editor NEW
106.0 8.0 68.0 64.91 MB

Flutter plugin support peer-to-peer connectivity and the discovery of nearby devices for Android vs IOS

Home Page: https://pub.dev/packages/flutter_nearby_connections

License: BSD 2-Clause "Simplified" License

Kotlin 33.48% Objective-C 1.21% Ruby 3.40% Swift 25.06% Dart 36.84%
ios android flutter flutter-plugin nearby-connection multiper-connectivity dart

flutter_nearby_connections's Introduction

flutter_nearby_connections

flutter nearby connections

Flutter plugin supports peer-to-peer connectivity and discovers nearby devices for Android and IOS

The flutter_nearby_connections plugin supports the discovery of services provided by nearby devices. Moreover, the flutter_nearby_connections plugin also supports communicating with those services through message-based data, streaming data, and resources (such as files). The framework uses infrastructure Wi-Fi networks, peer-to-peer Wi-Fi and Bluetooth Personal Area Networks (PAN) for the underlying transport over UDP. The project is based on

Android

Nearby Connections API (Bluetooth & hotspot) Support Strategy: Strategy.P2P_CLUSTER, Strategy.P2P_STAR, Strategy.P2P_POINT_TO_POINT

Wi-Fi P2P (only wifi hotspot no internet) Support Strategy: Strategy.Wi_Fi_P2P

IOS

Multipeer Connectivity

We use the NearbyConnections API, but Flutter methods are based on the concept of Multipeer Connectivity IOS.

Methods provided:

startAdvertisingPeer, startBrowsingForPeers, stopAdvertisingPeer

We separate the dependencies of the MCNearbyServiceAdvertiser, MCNearbyServiceBrowser and MCSession classes. All of the methods will be implemented in the NearbyService class.

Noted

  • Android doesn't support emulator only support real devices
  • On iOS 14, need to define in Info.plist
    <key>NSBonjourServices</key>
    <array>
        <string>_{YOUR_SERVICE_TYPE}._tcp</string>
    </array>
    <key>UIRequiresPersistentWiFi</key>
    <true/>
    <key>NSBluetoothAlwaysUsageDescription</key>
    <string>{YOUR_DESCRIPTION}</string>

in this case, YOUR_SERVICE_TYPE is 'mp-connection' (you can define it)

nearbyService.init(
        serviceType: 'mp-connection',
        strategy: Strategy.P2P_CLUSTER,

Test on IOS device

The example app running in IOS

Test on Android device

The example app running in Android

Visitors Count

Loading

flutter_nearby_connections's People

Contributors

cor277 avatar darthsid12 avatar harrynguyen-vmo avatar juanxcueva avatar vietdq2701 avatar vnapnic avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

flutter_nearby_connections's Issues

Zero Documentation

The Documentation to this Library is extremely lacking and it's very hard to understand what the example does.
Could you please go through your example and add with // comments, what each code block exactly does?
It would make it a lot easier to understand and implement at other places.
https://pub.dev/packages/flutter_nearby_connections/example

This fix would take roughly 10 minutes, as you are the one who already understands the code and know what each line does.
Eventually, if I have enough time and energy to look at it, I may be able to make a some sort of documentation.
This is my impression of the code:

At the beginning the devices decide, whether they are a browser (searcher)
or an advertiser.
the browser will find other advertisers on the list,
which the advertiser only waits until he gets connected.
Then both can send messages to each other, once the connection has been established.

Initializing & Settings
Here are all Settings declared, which are meant required for a
successfull Peer-to-Peer connection.

For Example we choose here the strategy, which is P2P_Cluster.
Once this action nearbyService is called,
it checks if the devicetype is browser.
Presumably this doesn't actually check IF the Device this program is used
on IS a Browser, but much rather if the device is currently
advertising or browsing / looking for other devices.

Either way it then stops searching for peers (other devices),
waits 200 microseconds, which is aproximately 0.002 seconds, until it starts browsing for peers again.

If the device turns out to be a "advertiser"
it stops advertising peers and stops browsing,
then waits 0.002 seconds until it starts
advertising peers and starts browsing.

await nearbyService.init(
        serviceType: 'mpconn',
        deviceName: devInfo,
        strategy: Strategy.P2P_CLUSTER,
        callback: (isRunning) async {
          if (isRunning) {
            if (widget.deviceType == DeviceType.browser) {
              await nearbyService.stopBrowsingForPeers();
              await Future.delayed(Duration(microseconds: 200));
              await nearbyService.startBrowsingForPeers();
            } else {
              await nearbyService.stopAdvertisingPeer();
              await nearbyService.stopBrowsingForPeers();
              await Future.delayed(Duration(microseconds: 200));
              await nearbyService.startAdvertisingPeer();
              await nearbyService.startBrowsingForPeers();
            }
          }
        });

Declarations

enum DeviceType { advertiser, browser }

class DevicesListScreen extends StatefulWidget {
  const DevicesListScreen({required this.deviceType});
final DeviceType deviceType;

class _DevicesListScreenState extends State<DevicesListScreen> {
  List<Device> devices = [];
  List<Device> connectedDevices = [];
  late NearbyService nearbyService;
  late StreamSubscription subscription;
  late StreamSubscription receivedDataSubscription;

Check for Android or IOS

nearbyService = NearbyService();
    String devInfo = '';
    DeviceInfoPlugin deviceInfo = DeviceInfoPlugin();
    
    //If this is android then this will be executed
    if (Platform.isAndroid) {
      AndroidDeviceInfo androidInfo = await deviceInfo.androidInfo;
      devInfo = androidInfo.model!;
    }

    //If this is run on IOS, then this will be executed
    if (Platform.isIOS) {
      IosDeviceInfo iosInfo = await deviceInfo.iosInfo;
      devInfo = iosInfo.localizedModel!;
    }

Start & End Connection

_onButtonClicked(Device device) {
    switch (device.state) {
      case SessionState.notConnected:
        nearbyService.invitePeer(
          deviceID: device.deviceId,
          deviceName: device.deviceName,
        );
        break;
        //If connected make a disconnection
      case SessionState.connected:
        nearbyService.disconnectPeer(deviceID: device.deviceId);
        break;
        //If it's during a connection ignore it
      case SessionState.connecting:
        break;
    }
  }

Subscription
If the subscriptionstate, aka the status of the connection between each other has changed, it wil print all elements of devices it has found and their state. (Basically if they're already connected or not.)

If this is run on an android device and the device is currently connected,
the searching for peers stops. Else if it's not connected the searching for peers starts.

subscription =
        nearbyService.stateChangedSubscription(callback: (devicesList) {
      devicesList.forEach((element) {
        print(
            " deviceId: ${element.deviceId} | deviceName: ${element.deviceName} | state: ${element.state}");

        if (Platform.isAndroid) {
          if (element.state == SessionState.connected) {
            nearbyService.stopBrowsingForPeers();
          } else {
            nearbyService.startBrowsingForPeers();
          }
        }
      });

      setState(() {
        devices.clear();
        devices.addAll(devicesList);
        connectedDevices.clear();
        connectedDevices.addAll(devicesList
            .where((d) => d.state == SessionState.connected)
            .toList());
      });
    });

Send Data

nearbyService.sendMessage(
device.deviceId, myController.text);
myController.text = '';

Received Data

receivedDataSubscription =
        nearbyService.dataReceivedSubscription(callback: (data) {
      print("dataReceivedSubscription: ${jsonEncode(data)}");
      showToast(jsonEncode(data),
          context: context,
          axis: Axis.horizontal,
          alignment: Alignment.center,
          position: StyledToastPosition.bottom);
    });

End search

void dispose() {
  subscription.cancel();
  receivedDataSubscription.cancel();
  nearbyService.stopBrowsingForPeers();
  nearbyService.stopAdvertisingPeer();
  super.dispose();
}

But it's still not clear what exactly.
Your code works great, but it's a mystery how it works.
Thanks.

Example not working [ANDROID]

I'm trying out your plugin, but the example app doesn't seem to work at all.
I'm using two real devices, both showing the WiFi direct notification, but neither seeing the other.

This si my flutter doctor output:
flutter_doctor

I'm probably missing something, but I can't figure it out
Permissionas are set, too.

Slowness (Wifi-direct not activated)

Hi, I am trying to implement file sharing for you. Indeed I managed to accomplish file sharing but the file-sharing is very slow. I am sure it is using a Bluetooth connection. I tried every strategy possible to switch to wifi direct, but no luck.

check this link: android/connectivity-samples#140

I have an idea for this problem, let me know when we can discuss it.

Issues with Flutter (Android) -> Native Android (Kotlin/Java) nearby connection.

Hey, I was trying to get a new flutter app to connect to an old / already made Android Native app written in Kotlin/Java, with the Kotlin side as the advertiser. But I couldn't get them to connect until I examined the code.

Setting the Service Name on the Kotlin side to "flutter_nearby_connections" made it connect, probably due to that name being hard wired into the Android plugin in Flutter Nearby Connections. ( const val SERVICE_ID = "flutter_nearby_connections" )

So the Native code became:

Nearby.getConnectionsClient(this).startAdvertising(
                    deviceShortInfoString,
                    "flutter_nearby_connections",
                    connectionLifecycleCallback,
                    advertisingOptions)

For a good while I tried to change the serviceType on the flutter side to be exactly the same as the advertiser service name but obviously that didn't work. Is that only for iOS?

So my question is: Would it be possible to pass in a custom string into the flutter code to set the service name to something other than flutter_nearby_connections? That would make it a lot easier to work with legacy code from android native, especially if you don't want cross-talk between two different nearby sessions. Which is something we have wanted in the past.

This app is using a deprecated version of the Android embedding.

Hello everybody

while doing

flutter run

in the example folder I get:

Warning
──────────────────────────────────────────────────────────────────────────────
Your Flutter application is created using an older version of the Android
embedding. It is being deprecated in favor of Android embedding v2. To migrate
your project, follow the steps at:

https://github.com/flutter/flutter/wiki/Upgrading-pre-1.12-Android-projects

━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
The detected reason was:

  /Users/eddy/projects/ttt/flutter_nearby_connections/example/android/app/src/main/AndroidManifest.xml uses
  `android:name="io.flutter.app.FlutterApplication"`
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━

Build failed due to use of deprecated Android v1 embedding.

is there any plan to upgrade this to the new embedding?
or
what is flutter most recent version that can be used to build and run the example?

iOS talk to Android and vice versa?

Not an issue, just a question, will this library allow for iOS devices to talk peer-to-peer with Android devices and vice versa? Is there an example that accounts for this?

Thanks, great work guys!

Running as a Foreground Task

We are in a scenerio where we need to implement this plugin in a foreground service combined with another flutter plugin.
flutter_foreground_task
On try to start discovery we are getting following errors

E/MethodChannel#nearby_connections( 5496): Failed to handle method call
E/MethodChannel#nearby_connections( 5496): java.lang.NullPointerException: Activity must not be null
E/MethodChannel#nearby_connections( 5496): at e.a.a.a.b.k.o.g(:11)
E/MethodChannel#nearby_connections( 5496): at e.a.a.a.f.a.a(:1)
E/MethodChannel#nearby_connections( 5496): at e.b.a.b.onMethodCall(:233)
E/MethodChannel#nearby_connections( 5496): at io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler.onMessage(:262)
E/MethodChannel#nearby_connections( 5496): at io.flutter.embedding.engine.dart.DartMessenger.invokeHandler(:295)
E/MethodChannel#nearby_connections( 5496): at io.flutter.embedding.engine.dart.DartMessenger.a(:319)
E/MethodChannel#nearby_connections( 5496): at io.flutter.embedding.engine.dart.DartMessenger.b(Unknown Source:0)
E/MethodChannel#nearby_connections( 5496): at f.a.a.b.b.c.run(Unknown Source:12)
E/MethodChannel#nearby_connections( 5496): at android.os.Handler.handleCallback(Handler.java:938)
E/MethodChannel#nearby_connections( 5496): at android.os.Handler.dispatchMessage(Handler.java:99)
E/MethodChannel#nearby_connections( 5496): at android.os.Looper.loopOnce(Looper.java:226)
E/MethodChannel#nearby_connections( 5496): at android.os.Looper.loop(Looper.java:313)
E/MethodChannel#nearby_connections( 5496): at android.app.ActivityThread.main(ActivityThread.java:8751)
E/MethodChannel#nearby_connections( 5496): at java.lang.reflect.Method.invoke(Native Method)
E/MethodChannel#nearby_connections( 5496): at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:571)
E/MethodChannel#nearby_connections( 5496): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1135)

Doesn't work on iOS 17

NSNetServiceBrowser did not search with error dict [{
NSNetServicesErrorCode = "-72008";
NSNetServicesErrorDomain = 10;
}].

Adopt/Merge with nearby_connections to work inside the package

Hello there, this is a great plugin and is just what I needed for an upcoming project but was lacking on the iOS side. However, it seems as though you are lacking the Android implementation of nearby_connections. Good thing though that there is a developer who has already done extensive work into a similar package like this but for Android only and is looking to have an iOS implementation => nearby_connections

Perhaps you could reach out to him and try to see if there is a way to merge the two plugins into one as it is possible it could save you some considerable development time.

Execution failed for task ':flutter_nearby_connections:compileReleaseKotlin'. > Compilation error. See log for more details

flutter run gives this

`e: /Users/akkay/Applications/flutter/.pub-cache/hosted/pub.dartlang.org/flutter_nearby_connections-1.1.1/android/src/main/kotlin/com/nankai/flutter_nearby_connections/NearbyService.kt: (97, 9): Class 'kotlin.Unit' was compiled with an incompatible version of Kotlin. The binary version of its metadata is 1.5.1, expected version is 1.1.15.
The class is loaded from /Users/akkay/.gradle/caches/transforms-2/files-2.1/24fa3aa8d2270e5eb067bbe36e9b7563/jetified-kotlin-stdlib-1.5.10.jar!/kotlin/Unit.class
e: /Users/akkay/Applications/flutter/.pub-cache/hosted/pub.dartlang.org/flutter_nearby_connections-1.1.1/android/src/main/kotlin/com/nankai/flutter_nearby_connections/NearbyService.kt: (98, 27): Class 'kotlin.Unit' was compiled with an incompatible version of Kotlin. The binary version of its metadata is 1.5.1, expected version is 1.1.15.
The class is loaded from /Users/akkay/.gradle/caches/transforms-2/files-2.1/24fa3aa8d2270e5eb067bbe36e9b7563/jetified-kotlin-stdlib-1.5.10.jar!/kotlin/Unit.class
e: /Users/akkay/Applications/flutter/.pub-cache/hosted/pub.dartlang.org/flutter_nearby_connections-1.1.1/android/src/main/kotlin/com/nankai/flutter_nearby_connections/NearbyService.kt: (107, 71): Unresolved reference: java
e: /Users/akkay/Applications/flutter/.pub-cache/hosted/pub.dartlang.org/flutter_nearby_connections-1.1.1/android/src/main/kotlin/com/nankai/flutter_nearby_connections/NearbyService.kt: (108, 21): Unresolved reference: createNotificationChannel
e: /Users/akkay/Applications/flutter/.pub-cache/hosted/pub.dartlang.org/flutter_nearby_connections-1.1.1/android/src/main/kotlin/com/nankai/flutter_nearby_connections/ServiceBindManager.kt: (24, 71): Unresolved reference: java
e: /Users/akkay/Applications/flutter/.pub-cache/hosted/pub.dartlang.org/flutter_nearby_connections-1.1.1/android/src/main/kotlin/com/nankai/flutter_nearby_connections/ServiceBindManager.kt: (30, 13): Class 'kotlin.Unit' was compiled with an incompatible version of Kotlin. The binary version of its metadata is 1.5.1, expected version is 1.1.15.
The class is loaded from /Users/akkay/.gradle/caches/transforms-2/files-2.1/24fa3aa8d2270e5eb067bbe36e9b7563/jetified-kotlin-stdlib-1.5.10.jar!/kotlin/Unit.class
e: /Users/akkay/Applications/flutter/.pub-cache/hosted/pub.dartlang.org/flutter_nearby_connections-1.1.1/android/src/main/kotlin/com/nankai/flutter_nearby_connections/ServiceBindManager.kt: (31, 21): Class 'kotlin.Unit' was compiled with an incompatible version of Kotlin. The binary version of its metadata is 1.5.1, expected version is 1.1.15.
The class is loaded from /Users/akkay/.gradle/caches/transforms-2/files-2.1/24fa3aa8d2270e5eb067bbe36e9b7563/jetified-kotlin-stdlib-1.5.10.jar!/kotlin/Unit.class
e: /Users/akkay/Applications/flutter/.pub-cache/hosted/pub.dartlang.org/flutter_nearby_connections-1.1.1/android/src/main/kotlin/com/nankai/flutter_nearby_connections/ServiceBindManager.kt: (32, 23): Class 'kotlin.Unit' was compiled with an incompatible version of Kotlin. The binary version of its metadata is 1.5.1, expected version is 1.1.15.
The class is loaded from /Users/akkay/.gradle/caches/transforms-2/files-2.1/24fa3aa8d2270e5eb067bbe36e9b7563/jetified-kotlin-stdlib-1.5.10.jar!/kotlin/Unit.class
e: /Users/akkay/Applications/flutter/.pub-cache/hosted/pub.dartlang.org/flutter_nearby_connections-1.1.1/android/src/main/kotlin/com/nankai/flutter_nearby_connections/ServiceBindManager.kt: (33, 21): Class 'kotlin.Unit' was compiled with an incompatible version of Kotlin. The binary version of its metadata is 1.5.1, expected version is 1.1.15.
The class is loaded from /Users/akkay/.gradle/caches/transforms-2/files-2.1/24fa3aa8d2270e5eb067bbe36e9b7563/jetified-kotlin-stdlib-1.5.10.jar!/kotlin/Unit.class
e: /Users/akkay/Applications/flutter/.pub-cache/hosted/pub.dartlang.org/flutter_nearby_connections-1.1.1/android/src/main/kotlin/com/nankai/flutter_nearby_connections/ServiceBindManager.kt: (38, 21): Class 'kotlin.Unit' was compiled with an incompatible version of Kotlin. The binary version of its metadata is 1.5.1, expected version is 1.1.15.
The class is loaded from /Users/akkay/.gradle/caches/transforms-2/files-2.1/24fa3aa8d2270e5eb067bbe36e9b7563/jetified-kotlin-stdlib-1.5.10.jar!/kotlin/Unit.class
e: /Users/akkay/Applications/flutter/.pub-cache/hosted/pub.dartlang.org/flutter_nearby_connections-1.1.1/android/src/main/kotlin/com/nankai/flutter_nearby_connections/ServiceBindManager.kt: (39, 21): Class 'kotlin.Unit' was compiled with an incompatible version of Kotlin. The binary version of its metadata is 1.5.1, expected version is 1.1.15.
The class is loaded from /Users/akkay/.gradle/caches/transforms-2/files-2.1/24fa3aa8d2270e5eb067bbe36e9b7563/jetified-kotlin-stdlib-1.5.10.jar!/kotlin/Unit.class
e: /Users/akkay/Applications/flutter/.pub-cache/hosted/pub.dartlang.org/flutter_nearby_connections-1.1.1/android/src/main/kotlin/com/nankai/flutter_nearby_connections/ServiceBindManager.kt: (44, 21): Class 'kotlin.Unit' was compiled with an incompatible version of Kotlin. The binary version of its metadata is 1.5.1, expected version is 1.1.15.
The class is loaded from /Users/akkay/.gradle/caches/transforms-2/files-2.1/24fa3aa8d2270e5eb067bbe36e9b7563/jetified-kotlin-stdlib-1.5.10.jar!/kotlin/Unit.class
e: /Users/akkay/Applications/flutter/.pub-cache/hosted/pub.dartlang.org/flutter_nearby_connections-1.1.1/android/src/main/kotlin/com/nankai/flutter_nearby_connections/ServiceBindManager.kt: (45, 21): Class 'kotlin.Unit' was compiled with an incompatible version of Kotlin. The binary version of its metadata is 1.5.1, expected version is 1.1.15.
The class is loaded from /Users/akkay/.gradle/caches/transforms-2/files-2.1/24fa3aa8d2270e5eb067bbe36e9b7563/jetified-kotlin-stdlib-1.5.10.jar!/kotlin/Unit.class
e: /Users/akkay/Applications/flutter/.pub-cache/hosted/pub.dartlang.org/flutter_nearby_connections-1.1.1/android/src/main/kotlin/com/nankai/flutter_nearby_connections/ServiceBindManager.kt: (50, 21): Class 'kotlin.Unit' was compiled with an incompatible version of Kotlin. The binary version of its metadata is 1.5.1, expected version is 1.1.15.
The class is loaded from /Users/akkay/.gradle/caches/transforms-2/files-2.1/24fa3aa8d2270e5eb067bbe36e9b7563/jetified-kotlin-stdlib-1.5.10.jar!/kotlin/Unit.class
e: /Users/akkay/Applications/flutter/.pub-cache/hosted/pub.dartlang.org/flutter_nearby_connections-1.1.1/android/src/main/kotlin/com/nankai/flutter_nearby_connections/ServiceBindManager.kt: (51, 21): Class 'kotlin.Unit' was compiled with an incompatible version of Kotlin. The binary version of its metadata is 1.5.1, expected version is 1.1.15.
The class is loaded from /Users/akkay/.gradle/caches/transforms-2/files-2.1/24fa3aa8d2270e5eb067bbe36e9b7563/jetified-kotlin-stdlib-1.5.10.jar!/kotlin/Unit.class
e: /Users/akkay/Applications/flutter/.pub-cache/hosted/pub.dartlang.org/flutter_nearby_connections-1.1.1/android/src/main/kotlin/com/nankai/flutter_nearby_connections/ServiceBindManager.kt: (58, 17): Class 'kotlin.Unit' was compiled with an incompatible version of Kotlin. The binary version of its metadata is 1.5.1, expected version is 1.1.15.
The class is loaded from /Users/akkay/.gradle/caches/transforms-2/files-2.1/24fa3aa8d2270e5eb067bbe36e9b7563/jetified-kotlin-stdlib-1.5.10.jar!/kotlin/Unit.class
e: /Users/akkay/Applications/flutter/.pub-cache/hosted/pub.dartlang.org/flutter_nearby_connections-1.1.1/android/src/main/kotlin/com/nankai/flutter_nearby_connections/ServiceBindManager.kt: (65, 25): Class 'kotlin.Unit' was compiled with an incompatible version of Kotlin. The binary version of its metadata is 1.5.1, expected version is 1.1.15.
The class is loaded from /Users/akkay/.gradle/caches/transforms-2/files-2.1/24fa3aa8d2270e5eb067bbe36e9b7563/jetified-kotlin-stdlib-1.5.10.jar!/kotlin/Unit.class
e: /Users/akkay/Applications/flutter/.pub-cache/hosted/pub.dartlang.org/flutter_nearby_connections-1.1.1/android/src/main/kotlin/com/nankai/flutter_nearby_connections/ServiceBindManager.kt: (66, 25): Class 'kotlin.Unit' was compiled with an incompatible version of Kotlin. The binary version of its metadata is 1.5.1, expected version is 1.1.15.
The class is loaded from /Users/akkay/.gradle/caches/transforms-2/files-2.1/24fa3aa8d2270e5eb067bbe36e9b7563/jetified-kotlin-stdlib-1.5.10.jar!/kotlin/Unit.class
e: /Users/akkay/Applications/flutter/.pub-cache/hosted/pub.dartlang.org/flutter_nearby_connections-1.1.1/android/src/main/kotlin/com/nankai/flutter_nearby_connections/ServiceBindManager.kt: (69, 15): Class 'kotlin.Unit' was compiled with an incompatible version of Kotlin. The binary version of its metadata is 1.5.1, expected version is 1.1.15.
The class is loaded from /Users/akkay/.gradle/caches/transforms-2/files-2.1/24fa3aa8d2270e5eb067bbe36e9b7563/jetified-kotlin-stdlib-1.5.10.jar!/kotlin/Unit.class
e: /Users/akkay/Applications/flutter/.pub-cache/hosted/pub.dartlang.org/flutter_nearby_connections-1.1.1/android/src/main/kotlin/com/nankai/flutter_nearby_connections/ServiceBindManager.kt: (71, 19): Class 'kotlin.Unit' was compiled with an incompatible version of Kotlin. The binary version of its metadata is 1.5.1, expected version is 1.1.15.
The class is loaded from /Users/akkay/.gradle/caches/transforms-2/files-2.1/24fa3aa8d2270e5eb067bbe36e9b7563/jetified-kotlin-stdlib-1.5.10.jar!/kotlin/Unit.class
e: /Users/akkay/Applications/flutter/.pub-cache/hosted/pub.dartlang.org/flutter_nearby_connections-1.1.1/android/src/main/kotlin/com/nankai/flutter_nearby_connections/ServiceBindManager.kt: (72, 19): Class 'kotlin.Unit' was compiled with an incompatible version of Kotlin. The binary version of its metadata is 1.5.1, expected version is 1.1.15.
The class is loaded from /Users/akkay/.gradle/caches/transforms-2/files-2.1/24fa3aa8d2270e5eb067bbe36e9b7563/jetified-kotlin-stdlib-1.5.10.jar!/kotlin/Unit.class

FAILURE: Build failed with an exception.

  • What went wrong:
    Execution failed for task ':flutter_nearby_connections:compileDebugKotlin'.

Compilation error. See log for more details

  • Try:
    Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

  • Get more help at https://help.gradle.org

BUILD FAILED in 20s
Exception: Gradle task assembleDebug failed with exit code 1
Exited (sigterm)
`

Using custom DeviceName in nearbyService.init

Hello there:) Is it possible to define the device name so that other devices see this name when I am discovered?
I've tried a string within nearbyService.init(DeviceName: "..." but the name of the discovered device has only been "Unknown".

Plugin stops working on Android 12 when targeting SDK version 31

Firstly thanks for this great Plugin, however, I have noticed an issue that it stops working when running on an Android phone with Android 12 and targeting SDK version 31.
So far targetSdkVersion 30 seems to be working still with compileSdkVersion set to 31.

This might be due to the new required permissions:

<!-- Only required for apps targeting Android 12 and higher -->
<uses-permission android:name="android.permission.BLUETOOTH_ADVERTISE" />
<uses-permission android:name="android.permission.BLUETOOTH_CONNECT" />
<uses-permission android:name="android.permission.BLUETOOTH_SCAN" />

Android example not working

Hi

I can get the ios sample working fine. If I try the Android it does not. I've used 2 physical devices (Nexus 5x) and a pair of simulators (Pixel 4) without luck.

I see this in the status bar on each Pixel 4 device.

Untitled

Browsing and advertising at the same time

Hi,

First of all thanks for this plugin. To let you know what I try to accomplish: imagine a room with 2 phones, when phone is on "scanning room" page, the phone will start advertising a custom ID (passed to deviceName) and at the same time browse for other users. During my testing, I've been able to see other phones, but not if I'm trying to browse AND advertise at the same time. Is that normal? I think yes, but to be sure I prefer to ask.

With this code I can't see any devices neither can be seen

await nearbyService.init(
      serviceType: 'mpconn',
      deviceName: devInfo,
      strategy: Strategy.P2P_CLUSTER,
      callback: (isRunning) async {
        if (isRunning) {
            await nearbyService.stopAdvertisingPeer();
            await nearbyService.stopBrowsingForPeers();
            await Future.delayed(Duration(microseconds: 200));
            await nearbyService.startAdvertisingPeer();
            await nearbyService.startBrowsingForPeers();
        }
      });

But if I'm commenting "startAdvertisingPeer()" on one device and "startBrowsingForPeer" on the other, I can see the device that is advertising perfectly with the one in "browsing mode".

Thank you

Doesn't work on some phones

I tried both advertising and browsing on 3 android devices running android 9, 6 and 7 (last one has a custom rom).
Only the android 9 can browse the others but not the opposite. The others cannot browse they can only advertise.

java.lang.IncompatibleClassChangeError: Found interface com.google.android.gms.nearby.connection.ConnectionsClient, but class was expected (declaration of 'com.google.android.gms.nearby.connection.ConnectionsClient'

FATAL EXCEPTION: main
E/AndroidRuntime(10222): Process: com.example.near_by_api_ex, PID: 10222
E/AndroidRuntime(10222): java.lang.IncompatibleClassChangeError: Found interface com.google.android.gms.nearby.connection.ConnectionsClient, but class was expected (declaration of 'com.google.android.gms.nearby.connection.ConnectionsClient' appears in /data/app/com.example.near_by_api_ex-SQmqvcjOXV3emcH2l_ILUw==/base.apk)
E/AndroidRuntime(10222): at com.nankai.flutter_nearby_connections.NearbyService.stopDiscovery(NearbyService.kt:72)
E/AndroidRuntime(10222): at com.nankai.flutter_nearby_connections.FlutterNearbyConnectionsPlugin.onMethodCall(FlutterNearbyConnectionsPlugin.kt:111)
E/AndroidRuntime(10222): at io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler.onMessage(MethodChannel.java:233)
E/AndroidRuntime(10222): at io.flutter.embedding.engine.dart.DartMessenger.handleMessageFromDart(DartMessenger.java:84)
E/AndroidRuntime(10222): at io.flutter.embedding.engine.FlutterJNI.handlePlatformMessage(FlutterJNI.java:865)
at android.os.MessageQueue.nativePollOnce(Native Method)
E/AndroidRuntime(10222): at android.os.MessageQueue.next(MessageQueue.java:336)
E/AndroidRuntime(10222): at android.os.Looper.loop(Looper.java:174)
E/AndroidRuntime(10222): at android.app.ActivityThread.main(ActivityThread.java:7356)
E/AndroidRuntime(10222): at java.lang.reflect.Method.invoke(Native Method)
E/AndroidRuntime(10222): at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:492)
E/AndroidRuntime(10222): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:930)
I/Process (10222): Sending signal. PID: 10222 SIG: 9

please i need help

Wrong deviceId

On receipt of a message from a peer, the Message contains deviceId and message. The deviceId is incorrect - it is the ID of the receiver of the message when it should be the deviceId of the sender. As far as I can tell, there is no way to determine the ID of the sender of a Message.

The Example app stops working after I updated the device to androd 12.

The Example app stopped working right after I updated the app to andriod 12.
I was using two google pixel 4A. I updated one of them to Andriod 12 and then the I needed to add the andriod:exported parameter in Manifest. and after installing the app new the browsing or the advertising is not working. The other phone can not discover the device anymore. The device would vibrate or notify everytime I clicked on brower or advertisement. But now it is not doing that either.

This could be a great help if someone could help me regarding this.

Can find between android and ios

It not a issues, I have a question about this package can can find between android device and ios device. I not need them connect, I just want to find them throught bluetooth or wifi.
Thanks.

Android 5 won't detect Android 11 advertising

I have 2 device (Android 5 and 11) and I tried testing them in each other.

The Android 11 device detects advertising of Android 5 but, it doesn't detect if Android 11 is the advertiser and Android 5 is the browser. It just don't detect.

Any ideas?

No code for file sharing

There is no code for file-sharing can anyone please provide it for this plugin will be really appericiated
Thanks in advance

Connections are impacted by other Bluetooth devices

Under Android, even when using Strategy.Wi_Fi_P2P, nearby_connections receives Bluetooth connection change callbacks from non-P2P devices, causing it to erroneously drop connections. In our case it is a Bluetooth low-energy device causing the issue. A good solution if possible might be to have nearby_connections check to see what device has issued the callback and to ignore connection dropped messages from non-connected devices..

Null Safety

Hi, Thank you for the great work you are doing. Please any plans for null-safety as this is the future of flutter ?

not working in Android Real Device

run example given in code in android real device,
its not showing any devices,

--
woking in ios simulator but not in android real device

Not working on android devices

Hi @VNAPNIC
First, thanks for taking the time to develop this plugin!
I tested this plugin on physical devices And I found that:

Works in case of

iOS to iOS

Doesn't wok in case of

Android to android
Android to iOS
Also the plugin is not requesting Nearby permission
I found also that the app requires the location permission but it doesn't ask for it , so I tried to authorize it manually but it doesn't fix the issue

Android not connecting.

Hi,

I was able to able to get the sample iOS working but the android I could not. Should android work and should cross platform work? If the answer is yes I can dig in further or help out.

Brad

Example App does not work on Samsung Galaxy A40 / Samsung Galaxy Tab A

I build the example app using Flutter 1.22 and loaded it to a Samasung Galaxy A40 phone and a Samsung Galaxy Tab A tablet. Both devices are in the same WLAN and Bluetooth is enabled.

The devices do not see each other, the example app does not list in "Browser"-mode the other device that is in "Advertise"-mode.

Plugin stops working on Android above version 12

It works well on real devices android version below 12 ,

trials as below:

  1. Tried to add these extra permission in the manifest as mentioned here [issue#29].
  1. tried to change device_info package with device_info_plus as mentioned here [issue#48].

still didn't work , any advices please,

Thanks in advanced.

Android device cannot detect others by flutter_nearby_connections

I want to connect between several devices, so I tried sample code provided by Flutter on debug mode.
As a result, I succeeded to connect between ios, but I didn't succeed between Android.Browser device couldn't detect Advertiser devices.

The Android device conditions used are as follows↓

Galaxy SC-02L (OS version: Android 10)
Google pixel 5a (OS version: Android 12)

Why don't I succeed to connect between Android? The diffence of OS version?? Please tell me the reason, and what should I do. Thank you for your help.

android/app/src/main/AndroidManifest.xml

<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.example.sample_record_audioplayer">
    <uses-permission android:name="android.permission.RECORD_AUDIO" />
    <uses-permission 
           android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
    <uses-permission android:name="android.permission.BLUETOOTH_SCAN" />
    <uses-permission android:name="android.permission.BLUETOOTH_CONNECT" />
    <application
        android:label="myapp"
        android:name="${applicationName}"
        android:icon="@mipmap/ic_launcher">
        <activity
            android:name=".MainActivity"
            android:exported="true"
            android:launchMode="singleTop"
            android:theme="@style/LaunchTheme"
            android:configChanges="orientation|keyboardHidden|keyboard|screenSize|smallestScreenSize|locale|layoutDirection|fontScale|screenLayout|density|uiMode"
            android:hardwareAccelerated="true"
            android:windowSoftInputMode="adjustResize">
            <!-- Specifies an Android theme to apply to this Activity as soon as
                 the Android process has started. This theme is visible to the user
                 while the Flutter UI initializes. After that, this theme continues
                 to determine the Window background behind the Flutter UI. -->
            <meta-data
              android:name="io.flutter.embedding.android.NormalTheme"
              android:resource="@style/NormalTheme"
              />
            <intent-filter>
                <action android:name="android.intent.action.MAIN"/>
                <category android:name="android.intent.category.LAUNCHER"/>
            </intent-filter>
        </activity>
        <!-- Don't delete the meta-data below.
             This is used by the Flutter tool to generate GeneratedPluginRegistrant.java -->
        <meta-data
            android:name="flutterEmbedding"
            android:value="2" />
    </application>
</manifest>

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.