mirror of
https://github.com/hackku21/nearby_connections.git
synced 2024-10-27 19:14:01 +00:00
release 0.0.1
This commit is contained in:
parent
9ff7aa546f
commit
5216e9c086
13
.vscode/launch.json
vendored
13
.vscode/launch.json
vendored
@ -1,13 +0,0 @@
|
|||||||
{
|
|
||||||
// Use IntelliSense to learn about possible attributes.
|
|
||||||
// Hover to view descriptions of existing attributes.
|
|
||||||
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
|
|
||||||
"version": "0.2.0",
|
|
||||||
"configurations": [
|
|
||||||
{
|
|
||||||
"name": "Flutter",
|
|
||||||
"request": "launch",
|
|
||||||
"type": "dart"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
@ -1,3 +1,6 @@
|
|||||||
## 0.0.1
|
## 0.0.1
|
||||||
|
|
||||||
* TODO: Describe initial release.
|
* Currently only bytes (max 32k array size) payload are supported
|
||||||
|
* Analogous to NearbyConnection library in Android with similar callback names and all
|
||||||
|
* Singleton pattern using factory constructor
|
||||||
|
|
||||||
|
26
LICENSE
26
LICENSE
@ -1 +1,25 @@
|
|||||||
TODO: Add your license here.
|
BSD 2-Clause License
|
||||||
|
|
||||||
|
Copyright (c) 2019, Prerak Mann
|
||||||
|
All rights reserved.
|
||||||
|
|
||||||
|
Redistribution and use in source and binary forms, with or without
|
||||||
|
modification, are permitted provided that the following conditions are met:
|
||||||
|
|
||||||
|
1. Redistributions of source code must retain the above copyright notice, this
|
||||||
|
list of conditions and the following disclaimer.
|
||||||
|
|
||||||
|
2. Redistributions in binary form must reproduce the above copyright notice,
|
||||||
|
this list of conditions and the following disclaimer in the documentation
|
||||||
|
and/or other materials provided with the distribution.
|
||||||
|
|
||||||
|
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||||
|
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||||
|
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||||
|
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
||||||
|
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||||
|
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||||
|
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||||
|
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||||
|
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||||
|
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||||
|
96
README.md
96
README.md
@ -5,6 +5,7 @@ An android flutter plugin for the Nearby Connections API
|
|||||||
## Getting Started
|
## Getting Started
|
||||||
|
|
||||||
### Set Permissions
|
### Set Permissions
|
||||||
|
Add these to AndroidManifest.xml
|
||||||
```xml
|
```xml
|
||||||
<!-- Required for Nearby Connections -->
|
<!-- Required for Nearby Connections -->
|
||||||
<uses-permission android:name="android.permission.BLUETOOTH" />
|
<uses-permission android:name="android.permission.BLUETOOTH" />
|
||||||
@ -16,3 +17,98 @@ An android flutter plugin for the Nearby Connections API
|
|||||||
```
|
```
|
||||||
Since ACCESS_FINE_LOCATION is considered to be dangerous system permissions, in addition to adding them to your manifest, you must request these permissions at runtime.
|
Since ACCESS_FINE_LOCATION 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
|
||||||
|
```java
|
||||||
|
// returns true/false asynchronously
|
||||||
|
bool a = await Nearby().checkPermissions()
|
||||||
|
|
||||||
|
// asks for permissions only if its not given
|
||||||
|
Nearby().askPermission()
|
||||||
|
```
|
||||||
|
|
||||||
|
### Working Flow
|
||||||
|
|
||||||
|
The working flow is similar to the [android nearby connections library](https://developers.google.com/nearby/connections/overviewoverview)
|
||||||
|
|
||||||
|
#### Advertise for connection
|
||||||
|
```dart
|
||||||
|
try {
|
||||||
|
bool a = await Nearby().startAdvertising(
|
||||||
|
userName,
|
||||||
|
strategy,
|
||||||
|
onConnectionInitiated: (String id,ConnectionInfo info) {
|
||||||
|
// Called whenever a discoverer requests connection
|
||||||
|
},
|
||||||
|
onConnectionResult: (String id,Status status) {
|
||||||
|
// Called when connection is accepted/rejected
|
||||||
|
},
|
||||||
|
onDisconnected: (id) {
|
||||||
|
// Callled whenever a discoverer disconnects from advertiser
|
||||||
|
},
|
||||||
|
);
|
||||||
|
} catch (exception) {
|
||||||
|
// platform exceptions like unable to start bluetooth or insufficient permissions
|
||||||
|
}
|
||||||
|
```
|
||||||
|
#### Discover Advertisers
|
||||||
|
```dart
|
||||||
|
try {
|
||||||
|
bool a = await Nearby().startDiscovery(
|
||||||
|
userName,
|
||||||
|
strategy,
|
||||||
|
onEndpointFound: (String id,String name, String serviceId) {
|
||||||
|
// called when an advertiser is found
|
||||||
|
},
|
||||||
|
onEndpointLost: (String id) {
|
||||||
|
//called when an advertiser is lost (only if we weren't connected to it )
|
||||||
|
},
|
||||||
|
);
|
||||||
|
} catch (e) {
|
||||||
|
// platform exceptions like unable to start bluetooth or insufficient permissions
|
||||||
|
}
|
||||||
|
```
|
||||||
|
#### Start and Stop Discovery
|
||||||
|
```dart
|
||||||
|
Nearby().stopAdvertising();
|
||||||
|
Nearby().stopDiscovery();
|
||||||
|
|
||||||
|
```
|
||||||
|
### Request Connection
|
||||||
|
```dart
|
||||||
|
// to be called by discover whenever an endpoint is found
|
||||||
|
// callbacks are similar to those in startAdvertising method
|
||||||
|
try{
|
||||||
|
Nearby().requestConnection(
|
||||||
|
userName,
|
||||||
|
id,
|
||||||
|
onConnectionInitiated: (id, info) {
|
||||||
|
},
|
||||||
|
onConnectionResult: (id, status) {
|
||||||
|
},
|
||||||
|
onDisconnected: (id) {
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}catch(exception){
|
||||||
|
// called if request was invalid
|
||||||
|
}
|
||||||
|
```
|
||||||
|
#### Accept Connections
|
||||||
|
```dart
|
||||||
|
Nearby().acceptConnection(
|
||||||
|
id,
|
||||||
|
onPayLoadRecieved: (endid,Uint8List bytes) {
|
||||||
|
// called whenever a payload is recieved.
|
||||||
|
},
|
||||||
|
);
|
||||||
|
```
|
||||||
|
### Sending Payload
|
||||||
|
|
||||||
|
```dart
|
||||||
|
Nearby().sendPayload(endpointId, bytes_array);
|
||||||
|
|
||||||
|
// payloads are recieved by callback given to acceptConnection method.
|
||||||
|
```
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -2,9 +2,6 @@ import 'dart:math';
|
|||||||
import 'dart:typed_data';
|
import 'dart:typed_data';
|
||||||
|
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'dart:async';
|
|
||||||
|
|
||||||
import 'package:flutter/services.dart';
|
|
||||||
import 'package:nearby_connections/nearby_connections.dart';
|
import 'package:nearby_connections/nearby_connections.dart';
|
||||||
|
|
||||||
void main() => runApp(MyApp());
|
void main() => runApp(MyApp());
|
||||||
|
@ -1,27 +0,0 @@
|
|||||||
// This is a basic Flutter widget test.
|
|
||||||
//
|
|
||||||
// To perform an interaction with a widget in your test, use the WidgetTester
|
|
||||||
// utility that Flutter provides. For example, you can send tap and scroll
|
|
||||||
// gestures. You can also use WidgetTester to find child widgets in the widget
|
|
||||||
// tree, read text, and verify that the values of widget properties are correct.
|
|
||||||
|
|
||||||
import 'package:flutter/material.dart';
|
|
||||||
import 'package:flutter_test/flutter_test.dart';
|
|
||||||
|
|
||||||
import 'package:nearby_connections_example/main.dart';
|
|
||||||
|
|
||||||
void main() {
|
|
||||||
testWidgets('Verify Platform version', (WidgetTester tester) async {
|
|
||||||
// Build our app and trigger a frame.
|
|
||||||
await tester.pumpWidget(MyApp());
|
|
||||||
|
|
||||||
// Verify that platform version is retrieved.
|
|
||||||
expect(
|
|
||||||
find.byWidgetPredicate(
|
|
||||||
(Widget widget) => widget is Text &&
|
|
||||||
widget.data.startsWith('Running on:'),
|
|
||||||
),
|
|
||||||
findsOneWidget,
|
|
||||||
);
|
|
||||||
});
|
|
||||||
}
|
|
43
pubspec.yaml
43
pubspec.yaml
@ -1,8 +1,8 @@
|
|||||||
name: nearby_connections
|
name: nearby_connections
|
||||||
description: A new Flutter plugin.
|
description: A new Flutter plugin.
|
||||||
version: 0.0.1
|
version: 0.0.1
|
||||||
author:
|
author: Prerak Mann <mannprerak2@gmail.com>
|
||||||
homepage:
|
homepage: https://github.com/mannprerak2/nearby_connections
|
||||||
|
|
||||||
environment:
|
environment:
|
||||||
sdk: ">=2.1.0 <3.0.0"
|
sdk: ">=2.1.0 <3.0.0"
|
||||||
@ -15,46 +15,7 @@ dev_dependencies:
|
|||||||
flutter_test:
|
flutter_test:
|
||||||
sdk: flutter
|
sdk: flutter
|
||||||
|
|
||||||
# For information on the generic Dart part of this file, see the
|
|
||||||
# following page: https://www.dartlang.org/tools/pub/pubspec
|
|
||||||
|
|
||||||
# The following section is specific to Flutter.
|
|
||||||
flutter:
|
flutter:
|
||||||
# This section identifies this Flutter project as a plugin project.
|
|
||||||
# The androidPackage and pluginClass identifiers should not ordinarily
|
|
||||||
# be modified. They are used by the tooling to maintain consistency when
|
|
||||||
# adding or updating assets for this project.
|
|
||||||
plugin:
|
plugin:
|
||||||
androidPackage: com.pkmnapps.nearby_connections
|
androidPackage: com.pkmnapps.nearby_connections
|
||||||
pluginClass: NearbyConnectionsPlugin
|
pluginClass: NearbyConnectionsPlugin
|
||||||
|
|
||||||
# To add assets to your plugin package, add an assets section, like this:
|
|
||||||
# assets:
|
|
||||||
# - images/a_dot_burr.jpeg
|
|
||||||
# - images/a_dot_ham.jpeg
|
|
||||||
#
|
|
||||||
# For details regarding assets in packages, see
|
|
||||||
# https://flutter.dev/assets-and-images/#from-packages
|
|
||||||
#
|
|
||||||
# An image asset can refer to one or more resolution-specific "variants", see
|
|
||||||
# https://flutter.dev/assets-and-images/#resolution-aware.
|
|
||||||
|
|
||||||
# To add custom fonts to your plugin package, add a fonts section here,
|
|
||||||
# in this "flutter" section. Each entry in this list should have a
|
|
||||||
# "family" key with the font family name, and a "fonts" key with a
|
|
||||||
# list giving the asset and other descriptors for the font. For
|
|
||||||
# example:
|
|
||||||
# fonts:
|
|
||||||
# - family: Schyler
|
|
||||||
# fonts:
|
|
||||||
# - asset: fonts/Schyler-Regular.ttf
|
|
||||||
# - asset: fonts/Schyler-Italic.ttf
|
|
||||||
# style: italic
|
|
||||||
# - family: Trajan Pro
|
|
||||||
# fonts:
|
|
||||||
# - asset: fonts/TrajanPro.ttf
|
|
||||||
# - asset: fonts/TrajanPro_Bold.ttf
|
|
||||||
# weight: 700
|
|
||||||
#
|
|
||||||
# For details regarding fonts in packages, see
|
|
||||||
# https://flutter.dev/custom-fonts/#from-packages
|
|
||||||
|
@ -1,6 +1,5 @@
|
|||||||
import 'package:flutter/services.dart';
|
import 'package:flutter/services.dart';
|
||||||
import 'package:flutter_test/flutter_test.dart';
|
import 'package:flutter_test/flutter_test.dart';
|
||||||
import 'package:nearby_connections/nearby_connections.dart';
|
|
||||||
|
|
||||||
void main() {
|
void main() {
|
||||||
const MethodChannel channel = MethodChannel('nearby_connections');
|
const MethodChannel channel = MethodChannel('nearby_connections');
|
||||||
|
Loading…
Reference in New Issue
Block a user