mirror of
https://github.com/hackku21/nearby_connections.git
synced 2024-10-27 19:14:01 +00:00
Published 1.0.1
Fixed file transfer and completed example app
This commit is contained in:
parent
598544d7d7
commit
38dc0080d0
@ -1,3 +1,8 @@
|
||||
## 1.0.1
|
||||
|
||||
* Changed convinience methods for asking permissions(location+storage)
|
||||
* Updated example
|
||||
|
||||
## 1.0.0
|
||||
|
||||
* Added support for Files (sendFilePayload)
|
||||
|
24
README.md
24
README.md
@ -35,13 +35,17 @@ Add these to AndroidManifest.xml
|
||||
```
|
||||
Since ACCESS_FINE_LOCATION and READ_EXTERNAL_STORAGE is considered to be dangerous system permissions, in addition to adding them to your manifest, you must request these permissions at runtime.
|
||||
|
||||
##### As a convinience the library provides methods to check and request location permissions
|
||||
#### As a **convinience** this library provides methods to check and request location and external read/write permissions
|
||||
```java
|
||||
// returns true/false asynchronously
|
||||
bool a = await Nearby().checkPermissions()
|
||||
bool a = await Nearby().checkLocationPermissions()
|
||||
// asks for permission only if its not given
|
||||
Nearby().askLocationPermission()
|
||||
|
||||
// asks for permissions only if its not given
|
||||
Nearby().askPermission()
|
||||
// OPTIONAL: if you need to transfer files and rename it on device
|
||||
Nearby().checkExternalStoragePermission()
|
||||
// asks for READ + WRTIE EXTERNAL STORAGE permission only if its not given
|
||||
Nearby().askExternalStoragePermission()
|
||||
```
|
||||
|
||||
## Work Flow
|
||||
@ -60,7 +64,7 @@ try {
|
||||
onConnectionResult: (String id,Status status) {
|
||||
// Called when connection is accepted/rejected
|
||||
},
|
||||
onDisconnected: (id) {
|
||||
onDisconnected: (String id) {
|
||||
// Callled whenever a discoverer disconnects from advertiser
|
||||
},
|
||||
);
|
||||
@ -74,7 +78,7 @@ try {
|
||||
bool a = await Nearby().startDiscovery(
|
||||
userName,
|
||||
strategy,
|
||||
onEndpointFound: (String id,String name, String serviceId) {
|
||||
onEndpointFound: (String id,String userName, String serviceId) {
|
||||
// called when an advertiser is found
|
||||
},
|
||||
onEndpointLost: (String id) {
|
||||
@ -120,6 +124,11 @@ Nearby().acceptConnection(
|
||||
onPayLoadRecieved: (endid,Uint8List bytes) {
|
||||
// called whenever a payload is recieved.
|
||||
},
|
||||
onPayloadTransferUpdate: (endid, payloadTransferUpdate) {
|
||||
// gives status of a payload
|
||||
// e.g success/failure/in_progress
|
||||
// bytes transferred and total bytes etc
|
||||
}
|
||||
);
|
||||
```
|
||||
## Sending Data
|
||||
@ -138,6 +147,7 @@ So you would need to rename the file on receivers end.
|
||||
|
||||
```dart
|
||||
//creates file with generic name (without extension) in Downloads Directory
|
||||
//its your responsibility to rename the file properly
|
||||
Nearby().sendFilePayload(endpointId, filePath);
|
||||
|
||||
//Send filename as well so that receiver can rename the file
|
||||
@ -150,7 +160,7 @@ 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
|
||||
Checkout the [**Example**](https://github.com/mannprerak2/nearby_connections/tree/master/example) in Repository for more details
|
||||
|
||||
|
||||
|
||||
|
@ -2,15 +2,8 @@
|
||||
|
||||
Demonstrates how to use the nearby_connections plugin.
|
||||
|
||||
## Getting Started
|
||||
Checkout the [**Example**](https://github.com/mannprerak2/nearby_connections/tree/master/example) repository for implementation of sending bytes and files.
|
||||
|
||||
This project is a starting point for a Flutter application.
|
||||
Other examples using this is
|
||||
- [Monoply Money Handler](https://github.com/mannprerak2/monopoly_money_game)
|
||||
|
||||
A few resources to get you started if this is your first Flutter project:
|
||||
|
||||
- [Lab: Write your first Flutter app](https://flutter.dev/docs/get-started/codelab)
|
||||
- [Cookbook: Useful Flutter samples](https://flutter.dev/docs/cookbook)
|
||||
|
||||
For help getting started with Flutter, view our
|
||||
[online documentation](https://flutter.dev/docs), which offers tutorials,
|
||||
samples, guidance on mobile development, and a full API reference.
|
||||
|
@ -19,7 +19,7 @@ class _MyAppState extends State<MyApp> {
|
||||
return MaterialApp(
|
||||
home: Scaffold(
|
||||
appBar: AppBar(
|
||||
title: const Text('Plugin example app'),
|
||||
title: const Text('Nearby Connections example app'),
|
||||
),
|
||||
body: Body(),
|
||||
),
|
||||
@ -35,9 +35,11 @@ class Body extends StatefulWidget {
|
||||
class _MyBodyState extends State<Body> {
|
||||
final String userName = Random().nextInt(10000).toString();
|
||||
final Strategy strategy = Strategy.P2P_STAR;
|
||||
|
||||
String cId = "0"; //currently connected device ID
|
||||
File tempFile; //stores the file being transferred
|
||||
Map<int, String> map = Map();
|
||||
File tempFile; //reference to the file currently being transferred
|
||||
Map<int, String> map =
|
||||
Map(); //store filename mapped to corresponding payloadId
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
@ -46,7 +48,9 @@ class _MyBodyState extends State<Body> {
|
||||
padding: const EdgeInsets.all(8.0),
|
||||
child: ListView(
|
||||
children: <Widget>[
|
||||
Text("Permissions",),
|
||||
Text(
|
||||
"Permissions",
|
||||
),
|
||||
Wrap(
|
||||
children: <Widget>[
|
||||
RaisedButton(
|
||||
@ -57,7 +61,8 @@ class _MyBodyState extends State<Body> {
|
||||
content: Text("Location permissions granted :)")));
|
||||
} else {
|
||||
Scaffold.of(context).showSnackBar(SnackBar(
|
||||
content: Text("Location permissions not granted :(")));
|
||||
content:
|
||||
Text("Location permissions not granted :(")));
|
||||
}
|
||||
},
|
||||
),
|
||||
@ -100,9 +105,7 @@ class _MyBodyState extends State<Body> {
|
||||
bool a = await Nearby().startAdvertising(
|
||||
userName,
|
||||
strategy,
|
||||
onConnectionInitiated: (id, info) {
|
||||
oci(id, info);
|
||||
},
|
||||
onConnectionInitiated: onConnectionInit,
|
||||
onConnectionResult: (id, status) {
|
||||
showSnackbar(status);
|
||||
},
|
||||
@ -110,7 +113,7 @@ class _MyBodyState extends State<Body> {
|
||||
showSnackbar("Disconnected: " + id);
|
||||
},
|
||||
);
|
||||
showSnackbar(a);
|
||||
showSnackbar("ADVERTISING: "+a.toString());
|
||||
} catch (exception) {
|
||||
showSnackbar(exception);
|
||||
}
|
||||
@ -134,7 +137,7 @@ class _MyBodyState extends State<Body> {
|
||||
userName,
|
||||
strategy,
|
||||
onEndpointFound: (id, name, serviceId) {
|
||||
print("in callback");
|
||||
// show sheet automatically to request connection
|
||||
showModalBottomSheet(
|
||||
context: context,
|
||||
builder: (builder) {
|
||||
@ -152,7 +155,7 @@ class _MyBodyState extends State<Body> {
|
||||
userName,
|
||||
id,
|
||||
onConnectionInitiated: (id, info) {
|
||||
oci(id, info);
|
||||
onConnectionInit(id, info);
|
||||
},
|
||||
onConnectionResult: (id, status) {
|
||||
showSnackbar(status);
|
||||
@ -170,10 +173,10 @@ class _MyBodyState extends State<Body> {
|
||||
);
|
||||
},
|
||||
onEndpointLost: (id) {
|
||||
showSnackbar(id);
|
||||
showSnackbar("Lost Endpoint:" + id);
|
||||
},
|
||||
);
|
||||
showSnackbar(a);
|
||||
showSnackbar("DISCOVERING: " + a.toString());
|
||||
} catch (e) {
|
||||
showSnackbar(e);
|
||||
}
|
||||
@ -194,7 +197,9 @@ class _MyBodyState extends State<Body> {
|
||||
},
|
||||
),
|
||||
Divider(),
|
||||
Text("Sending Data",),
|
||||
Text(
|
||||
"Sending Data",
|
||||
),
|
||||
RaisedButton(
|
||||
child: Text("Send Random Bytes Payload"),
|
||||
onPressed: () async {
|
||||
@ -231,8 +236,9 @@ class _MyBodyState extends State<Body> {
|
||||
));
|
||||
}
|
||||
|
||||
/// Called on a Connection request (on both devices)
|
||||
void oci(String id, ConnectionInfo info) {
|
||||
/// Called upon Connection request (on both devices)
|
||||
/// Both need to accept connection to start sending/receiving
|
||||
void onConnectionInit(String id, ConnectionInfo info) {
|
||||
showModalBottomSheet(
|
||||
context: context,
|
||||
builder: (builder) {
|
||||
@ -290,7 +296,7 @@ class _MyBodyState extends State<Body> {
|
||||
PayloadStatus.SUCCESS) {
|
||||
showSnackbar(
|
||||
"success, total bytes = ${payloadTransferUpdate.totalBytes}");
|
||||
|
||||
|
||||
if (map.containsKey(payloadTransferUpdate.id)) {
|
||||
//rename the file now
|
||||
String name = map[payloadTransferUpdate.id];
|
||||
|
@ -73,7 +73,7 @@ packages:
|
||||
path: ".."
|
||||
relative: true
|
||||
source: path
|
||||
version: "1.0.0"
|
||||
version: "1.0.1"
|
||||
path:
|
||||
dependency: transitive
|
||||
description:
|
||||
|
@ -1,6 +1,6 @@
|
||||
name: nearby_connections
|
||||
description: Plugin for the android NearbyConnections API. Bytes and Files Supported.
|
||||
version: 1.0.0
|
||||
version: 1.0.1
|
||||
author: Prerak Mann <mannprerak2@gmail.com>
|
||||
homepage: https://github.com/mannprerak2/nearby_connections
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user