From dcd86e885f5e3682a9c7880e2ba7e0ff01333f34 Mon Sep 17 00:00:00 2001 From: Prerak Mann Date: Mon, 12 Aug 2019 00:37:27 +0530 Subject: [PATCH] published 1.0.0 --- README.md | 11 ++++++++--- .../nearby_connections/NearbyConnectionsPlugin.java | 5 ++++- lib/src/classes.dart | 9 +++++++++ lib/src/nearby_connections.dart | 4 +++- 4 files changed, 24 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 6b8aeaa..b23270d 100644 --- a/README.md +++ b/README.md @@ -132,15 +132,20 @@ File is stored in DOWNLOAD_DIRECTORY and given a generic name So you would need to rename the file on receivers end. ```dart - //creates file with generic name (without extension) in Downloads Directory Nearby().sendFilePayload(endpointId, filePath); //Send filename as well so that receiver can rename the file -Nearby().sendBytesPayload(endpointId,fileNameEncoded); +Nearby().sendBytesPayload(endpointId,fileNameEncodedWithPayloadId); +//e.g send a string like "payloadId:FileExtensionOrName" as bytes -// payloads are recieved by callback given to acceptConnection method. +//payloads are recieved by callback given to acceptConnection method. ``` +Every payload has an **ID** which is same for sender and receiver. + +You can get the absolute FilePath from Payload in *onPayloadReceived* function + +Check **Example** in Repository for more details diff --git a/android/src/main/java/com/pkmnapps/nearby_connections/NearbyConnectionsPlugin.java b/android/src/main/java/com/pkmnapps/nearby_connections/NearbyConnectionsPlugin.java index d9231ef..ac830d4 100644 --- a/android/src/main/java/com/pkmnapps/nearby_connections/NearbyConnectionsPlugin.java +++ b/android/src/main/java/com/pkmnapps/nearby_connections/NearbyConnectionsPlugin.java @@ -352,12 +352,15 @@ public class NearbyConnectionsPlugin implements MethodCallHandler { args.put("endpointId", endpointId); args.put("payloadId", payload.getId()); args.put("type", payload.getType()); - + if (payload.getType() == Payload.Type.BYTES) { byte[] bytes = payload.asBytes(); assert bytes != null; args.put("bytes", bytes); } + else if (payload.getType() == Payload.Type.BYTES) { + args.put("filePath", payload.asFile().asJavaFile().getAbsolutePath()); + } channel.invokeMethod("onPayloadReceived", args); } diff --git a/lib/src/classes.dart b/lib/src/classes.dart index 4633f09..1c78a67 100644 --- a/lib/src/classes.dart +++ b/lib/src/classes.dart @@ -4,15 +4,24 @@ import 'dart:typed_data'; import 'package:nearby_connections/src/defs.dart'; /// Bytes may be null if [Payload.type] is not [PayloadType.BYTES] +/// File may be null if [Payload.type] is not [PayloadType.FILE] +/// +/// Filepath is the complete filepath(with name) of the file +/// +/// The file at this location is incomplete until payloadTransferUpdate +/// gives SUCCESS for this payloadId class Payload { int id; PayloadType type; + Uint8List bytes; + String filePath; Payload({ this.id, this.bytes, this.type = PayloadType.NONE, + this.filePath, }); } diff --git a/lib/src/nearby_connections.dart b/lib/src/nearby_connections.dart index 86f4960..695c65b 100644 --- a/lib/src/nearby_connections.dart +++ b/lib/src/nearby_connections.dart @@ -96,11 +96,13 @@ class Nearby { int type = args['type']; Uint8List bytes = args['bytes']; int payloadId = args['payloadId']; + String filePath = args['filePath']; Payload payload = Payload( type: PayloadType.values[type], bytes: bytes, id: payloadId, + filePath: filePath, ); _onPayloadReceived?.call(endpointId, payload); @@ -342,4 +344,4 @@ class Nearby { }, ); } -} \ No newline at end of file +}