added serviceId parameter to startAdvertising and startDiscovery methods

This commit is contained in:
Prerak Mann 2019-12-18 15:37:26 +05:30
parent 59ca0c8292
commit e0b80b75fc
2 changed files with 26 additions and 17 deletions

View File

@ -114,14 +114,18 @@ public class NearbyConnectionsPlugin implements MethodCallHandler {
case "startAdvertising": {
String userNickName = (String) call.argument("userNickName");
int strategy = (int) call.argument("strategy");
String serviceId = (String) call.argument("serviceId");
assert userNickName != null;
if(serviceId==null || serviceId =="")
serviceId=SERVICE_ID;
AdvertisingOptions advertisingOptions = new AdvertisingOptions.Builder()
.setStrategy(getStrategy(strategy)).build();
Nearby.getConnectionsClient(activity)
.startAdvertising(
userNickName, SERVICE_ID, advertConnectionLifecycleCallback, advertisingOptions)
userNickName, serviceId, advertConnectionLifecycleCallback, advertisingOptions)
.addOnSuccessListener(new OnSuccessListener<Void>() {
@Override
public void onSuccess(Void aVoid) {
@ -140,12 +144,16 @@ public class NearbyConnectionsPlugin implements MethodCallHandler {
case "startDiscovery": {
String userNickName = (String) call.argument("userNickName");
int strategy = (int) call.argument("strategy");
String serviceId = (String) call.argument("serviceId");
assert userNickName != null;
if(serviceId==null || serviceId =="")
serviceId=SERVICE_ID;
DiscoveryOptions discoveryOptions =
new DiscoveryOptions.Builder().setStrategy(getStrategy(strategy)).build();
Nearby.getConnectionsClient(activity)
.startDiscovery(SERVICE_ID, endpointDiscoveryCallback, discoveryOptions)
.startDiscovery(serviceId, endpointDiscoveryCallback, discoveryOptions)
.addOnSuccessListener(new OnSuccessListener<Void>() {
@Override
public void onSuccess(Void aVoid) {

View File

@ -156,9 +156,8 @@ class Nearby {
/// Convinience method
///
/// Asks location permission
Future<void> askLocationPermission() async => await _channel.invokeMethod(
'askLocationPermission',
);
void askLocationPermission() =>
_channel.invokeMethod('askLocationPermission');
/// Convinience method
///
@ -171,21 +170,18 @@ class Nearby {
/// Convinience method
///
/// Asks external storage permission, required for file
Future<void> askExternalStoragePermission() async =>
await _channel.invokeMethod(
'askExternalStoragePermission',
);
void askExternalStoragePermission() =>
_channel.invokeMethod('askExternalStoragePermission');
/// Convinience method
///
/// Use this instead of calling both [askLocationPermission()] and [askExternalStoragePermission()]
Future<void> askLocationAndExternalStoragePermission() async =>
await _channel.invokeMethod(
'askLocationAndExternalStoragePermission',
);
void askLocationAndExternalStoragePermission() =>
_channel.invokeMethod('askLocationAndExternalStoragePermission');
/// Start Advertising, Discoverers would be able to discover this advertiser.
///
/// [serviceId] is a unique identifier for your app, its recommended to use your app package name only, it cannot be null
/// [userNickName] and [strategy] should not be null
Future<bool> startAdvertising(
String userNickName,
@ -193,8 +189,9 @@ class Nearby {
@required OnConnctionInitiated onConnectionInitiated,
@required OnConnectionResult onConnectionResult,
@required OnDisconnected onDisconnected,
String serviceId = "com.pkmnapps.nearby_connections",
}) async {
assert(userNickName != null && strategy != null);
assert(userNickName != null && strategy != null && serviceId != null);
this._advertConnectionInitiated = onConnectionInitiated;
this._advertConnectionResult = onConnectionResult;
@ -202,7 +199,8 @@ class Nearby {
return await _channel.invokeMethod('startAdvertising', <String, dynamic>{
'userNickName': userNickName,
'strategy': strategy.index
'strategy': strategy.index,
'serviceId': serviceId,
});
}
@ -218,20 +216,23 @@ class Nearby {
/// Start Discovery, You will now be able to discover the advertisers now.
///
/// [serviceId] is a unique identifier for your app, its recommended to use your app package name only, it cannot be null
/// [userNickName] and [strategy] should not be null
Future<bool> startDiscovery(
String userNickName,
Strategy strategy, {
@required OnEndpointFound onEndpointFound,
@required OnEndpointLost onEndpointLost,
String serviceId = "com.pkmnapps.nearby_connections",
}) async {
assert(userNickName != null && strategy != null);
assert(userNickName != null && strategy != null && serviceId != null);
this._onEndpointFound = onEndpointFound;
this._onEndpointLost = onEndpointLost;
return await _channel.invokeMethod('startDiscovery', <String, dynamic>{
'userNickName': userNickName,
'strategy': strategy.index
'strategy': strategy.index,
'serviceId': serviceId,
});
}