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 6da82ca..c16b379 100644 --- a/android/src/main/java/com/pkmnapps/nearby_connections/NearbyConnectionsPlugin.java +++ b/android/src/main/java/com/pkmnapps/nearby_connections/NearbyConnectionsPlugin.java @@ -216,8 +216,7 @@ public class NearbyConnectionsPlugin implements MethodCallHandler { assert endpointId != null; assert bytes != null; - String hello = "okay"; - Nearby.getConnectionsClient(activity).sendPayload(endpointId, Payload.fromBytes(hello.getBytes())); + Nearby.getConnectionsClient(activity).sendPayload(endpointId, Payload.fromBytes(bytes)); Log.d("NearbyCon java", "sentPayload"); break; diff --git a/example/lib/main.dart b/example/lib/main.dart index a1669b4..727482a 100644 --- a/example/lib/main.dart +++ b/example/lib/main.dart @@ -40,7 +40,6 @@ class _MyBodyState extends State { @override Widget build(BuildContext context) { - // TODO: implement build return Center( child: Column( children: [ @@ -71,34 +70,7 @@ class _MyBodyState extends State { userName, strategy, onConnectionInitiated: (id, info) { - showModalBottomSheet( - context: context, - builder: (builder) { - return Center( - child: Column( - children: [ - Text("id: " + id), - Text("Token: " + info.authenticationToken), - Text("Name" + info.endpointName), - Text("Incoming: " + - info.isIncomingConnection.toString()), - RaisedButton( - child: Text("Accept Connection"), - onPressed: () { - Nearby().acceptConnection(id); - }, - ), - RaisedButton( - child: Text("Reject Connection"), - onPressed: () { - Nearby().rejectConnection(id); - }, - ), - ], - ), - ); - }, - ); + oci(id, info); }, onConnectionResult: (id, status) { showSnackbar(status); @@ -145,53 +117,7 @@ class _MyBodyState extends State { userName, id, onConnectionInitiated: (id, info) { - showModalBottomSheet( - context: context, - builder: (builder) { - return Center( - child: Column( - children: [ - Text("id: " + id), - Text("Token: " + - info.authenticationToken), - Text( - "Name" + info.endpointName), - Text("Incoming: " + - info.isIncomingConnection - .toString()), - RaisedButton( - child: - Text("Accept Connection"), - onPressed: () { - cId = id; - Nearby().acceptConnection( - id, - onPayLoadRecieved: - (id, bytes) { - showSnackbar(id + - ": " + - String - .fromCharCodes( - bytes)); - }, - ); - }, - ), - RaisedButton( - child: - Text("Reject Connection"), - onPressed: () { - Navigator.pop(context); - - Nearby() - .rejectConnection(id); - }, - ), - ], - ), - ); - }, - ); + oci(id, info); }, onConnectionResult: (id, status) { showSnackbar(status); @@ -234,7 +160,7 @@ class _MyBodyState extends State { child: Text("Send Random Payload"), onPressed: () async { String a = Random().nextInt(100).toString(); - showSnackbar("Sending $a"); + showSnackbar("Sending $a to $cId"); Nearby().sendPayload(cId, Uint8List.fromList(a.codeUnits)); }, ), @@ -248,4 +174,43 @@ class _MyBodyState extends State { content: Text(a.toString()), )); } + + void oci(String id, ConnectionInfo info) { + showModalBottomSheet( + context: context, + builder: (builder) { + return Center( + child: Column( + children: [ + Text("id: " + id), + Text("Token: " + info.authenticationToken), + Text("Name" + info.endpointName), + Text("Incoming: " + info.isIncomingConnection.toString()), + RaisedButton( + child: Text("Accept Connection"), + onPressed: () { + Navigator.pop(context); + cId = id; + Nearby().acceptConnection( + id, + onPayLoadRecieved: (endid, bytes) { + showSnackbar(endid + ": " + String.fromCharCodes(bytes)); + }, + ); + }, + ), + RaisedButton( + child: Text("Reject Connection"), + onPressed: () { + Navigator.pop(context); + + Nearby().rejectConnection(id); + }, + ), + ], + ), + ); + }, + ); + } }