mirror of
https://github.com/hackku21/nearby_connections.git
synced 2026-03-02 03:49:22 +00:00
working, reason unknown
This commit is contained in:
@@ -33,6 +33,7 @@ import io.flutter.plugin.common.MethodChannel.Result;
|
||||
import io.flutter.plugin.common.PluginRegistry.Registrar;
|
||||
|
||||
import android.util.Log;
|
||||
|
||||
/**
|
||||
* NearbyConnectionsPlugin
|
||||
*/
|
||||
@@ -86,22 +87,23 @@ public class NearbyConnectionsPlugin implements MethodCallHandler {
|
||||
int strategy = (int) call.argument("strategy");
|
||||
|
||||
assert userNickName != null;
|
||||
Nearby.getConnectionsClient(activity).startAdvertising(
|
||||
userNickName,
|
||||
SERVICE_ID,
|
||||
advertConnectionLifecycleCallback,
|
||||
new AdvertisingOptions.Builder().setStrategy(getStrategy(strategy)).build())
|
||||
AdvertisingOptions advertisingOptions = new AdvertisingOptions.Builder()
|
||||
.setStrategy(getStrategy(strategy)).build();
|
||||
|
||||
Nearby.getConnectionsClient(activity)
|
||||
.startAdvertising(
|
||||
userNickName, SERVICE_ID, advertConnectionLifecycleCallback, advertisingOptions)
|
||||
.addOnSuccessListener(new OnSuccessListener<Void>() {
|
||||
@Override
|
||||
public void onSuccess(Void aVoid) {
|
||||
Log.d("NearbyCon java","started advertising");
|
||||
result.success(true);
|
||||
|
||||
}
|
||||
})
|
||||
.addOnFailureListener(new OnFailureListener() {
|
||||
@Override
|
||||
public void onFailure(@NonNull Exception e) {
|
||||
result.error("Failure", e.getMessage(), null);
|
||||
result.success(false);
|
||||
}
|
||||
});
|
||||
break;
|
||||
@@ -111,32 +113,31 @@ public class NearbyConnectionsPlugin implements MethodCallHandler {
|
||||
int strategy = (int) call.argument("strategy");
|
||||
|
||||
assert userNickName != null;
|
||||
Nearby.getConnectionsClient(activity).startDiscovery(
|
||||
userNickName,
|
||||
endpointDiscoveryCallback,
|
||||
new DiscoveryOptions.Builder().setStrategy(getStrategy(strategy)).build())
|
||||
DiscoveryOptions discoveryOptions =
|
||||
new DiscoveryOptions.Builder().setStrategy(getStrategy(strategy)).build();
|
||||
Nearby.getConnectionsClient(activity)
|
||||
.startDiscovery(SERVICE_ID, endpointDiscoveryCallback, discoveryOptions)
|
||||
.addOnSuccessListener(new OnSuccessListener<Void>() {
|
||||
@Override
|
||||
public void onSuccess(Void aVoid) {
|
||||
Log.d("NearbyCon java","started discovery");
|
||||
result.success(true);
|
||||
}
|
||||
})
|
||||
.addOnFailureListener(new OnFailureListener() {
|
||||
@Override
|
||||
public void onFailure(@NonNull Exception e) {
|
||||
result.error("Failure", e.getMessage(), null);
|
||||
result.success(false);
|
||||
}
|
||||
});
|
||||
break;
|
||||
}
|
||||
case "stopAllEndpoints":
|
||||
Log.d("NearbyCon java","stopAllEndpoints");
|
||||
Log.d("NearbyCon java", "stopAllEndpoints");
|
||||
Nearby.getConnectionsClient(activity).stopAllEndpoints();
|
||||
result.success(null);
|
||||
break;
|
||||
case "disconnectFromEndpoint": {
|
||||
Log.d("NearbyCon java","disconnectFromEndpoint");
|
||||
Log.d("NearbyCon java", "disconnectFromEndpoint");
|
||||
String endpointId = call.argument("endpointId");
|
||||
assert endpointId != null;
|
||||
Nearby.getConnectionsClient(activity).disconnectFromEndpoint(endpointId);
|
||||
@@ -144,7 +145,7 @@ public class NearbyConnectionsPlugin implements MethodCallHandler {
|
||||
break;
|
||||
}
|
||||
case "requestConnection": {
|
||||
Log.d("NearbyCon java","requestConnection");
|
||||
Log.d("NearbyCon java", "requestConnection");
|
||||
String userNickName = (String) call.argument("userNickName");
|
||||
String endpointId = (String) call.argument("endpointId");
|
||||
|
||||
@@ -206,7 +207,7 @@ public class NearbyConnectionsPlugin implements MethodCallHandler {
|
||||
});
|
||||
break;
|
||||
}
|
||||
case "sendPayload":{
|
||||
case "sendPayload": {
|
||||
//Nearby.getConnectionsClient(activity).sendPayload()
|
||||
break;
|
||||
}
|
||||
@@ -218,7 +219,7 @@ public class NearbyConnectionsPlugin implements MethodCallHandler {
|
||||
private final ConnectionLifecycleCallback advertConnectionLifecycleCallback = new ConnectionLifecycleCallback() {
|
||||
@Override
|
||||
public void onConnectionInitiated(@NonNull String endpointId, @NonNull ConnectionInfo connectionInfo) {
|
||||
Log.d("NearbyCon java","ad.onConnectionInitiated");
|
||||
Log.d("NearbyCon java", "ad.onConnectionInitiated");
|
||||
Map<String, Object> args = new HashMap<>();
|
||||
args.put("endpointId", endpointId);
|
||||
args.put("endpointName", connectionInfo.getEndpointName());
|
||||
@@ -229,7 +230,7 @@ public class NearbyConnectionsPlugin implements MethodCallHandler {
|
||||
|
||||
@Override
|
||||
public void onConnectionResult(@NonNull String endpointId, @NonNull ConnectionResolution connectionResolution) {
|
||||
Log.d("NearbyCon java","ad.onConnectionResult");
|
||||
Log.d("NearbyCon java", "ad.onConnectionResult");
|
||||
Map<String, Object> args = new HashMap<>();
|
||||
args.put("endpointId", endpointId);
|
||||
int statusCode = -1;
|
||||
@@ -255,7 +256,7 @@ public class NearbyConnectionsPlugin implements MethodCallHandler {
|
||||
|
||||
@Override
|
||||
public void onDisconnected(@NonNull String endpointId) {
|
||||
Log.d("NearbyCon java","ad.onDisconnected");
|
||||
Log.d("NearbyCon java", "ad.onDisconnected");
|
||||
Map<String, Object> args = new HashMap<>();
|
||||
args.put("endpointId", endpointId);
|
||||
channel.invokeMethod("ad.onDisconnected", args);
|
||||
@@ -265,7 +266,7 @@ public class NearbyConnectionsPlugin implements MethodCallHandler {
|
||||
private final ConnectionLifecycleCallback discoverConnectionLifecycleCallback = new ConnectionLifecycleCallback() {
|
||||
@Override
|
||||
public void onConnectionInitiated(@NonNull String endpointId, @NonNull ConnectionInfo connectionInfo) {
|
||||
Log.d("NearbyCon java","dis.onConnectionInitiated");
|
||||
Log.d("NearbyCon java", "dis.onConnectionInitiated");
|
||||
Map<String, Object> args = new HashMap<>();
|
||||
args.put("endpointId", endpointId);
|
||||
args.put("endpointName", connectionInfo.getEndpointName());
|
||||
@@ -276,7 +277,7 @@ public class NearbyConnectionsPlugin implements MethodCallHandler {
|
||||
|
||||
@Override
|
||||
public void onConnectionResult(@NonNull String endpointId, @NonNull ConnectionResolution connectionResolution) {
|
||||
Log.d("NearbyCon java","dis.onConnectionResult");
|
||||
Log.d("NearbyCon java", "dis.onConnectionResult");
|
||||
Map<String, Object> args = new HashMap<>();
|
||||
args.put("endpointId", endpointId);
|
||||
int statusCode = -1;
|
||||
@@ -302,7 +303,7 @@ public class NearbyConnectionsPlugin implements MethodCallHandler {
|
||||
|
||||
@Override
|
||||
public void onDisconnected(@NonNull String endpointId) {
|
||||
Log.d("NearbyCon java","dis.onDisconnected");
|
||||
Log.d("NearbyCon java", "dis.onDisconnected");
|
||||
Map<String, Object> args = new HashMap<>();
|
||||
args.put("endpointId", endpointId);
|
||||
channel.invokeMethod("dis.onDisconnected", args);
|
||||
@@ -324,7 +325,7 @@ public class NearbyConnectionsPlugin implements MethodCallHandler {
|
||||
private final EndpointDiscoveryCallback endpointDiscoveryCallback = new EndpointDiscoveryCallback() {
|
||||
@Override
|
||||
public void onEndpointFound(@NonNull String endpointId, @NonNull DiscoveredEndpointInfo discoveredEndpointInfo) {
|
||||
Log.d("NearbyCon java","onEndpointFound");
|
||||
Log.d("NearbyCon java", "onEndpointFound");
|
||||
Map<String, Object> args = new HashMap<>();
|
||||
args.put("endpointId", endpointId);
|
||||
args.put("endpointName", discoveredEndpointInfo.getEndpointName());
|
||||
@@ -334,7 +335,7 @@ public class NearbyConnectionsPlugin implements MethodCallHandler {
|
||||
|
||||
@Override
|
||||
public void onEndpointLost(@NonNull String endpointId) {
|
||||
Log.d("NearbyCon java","onEndpointLost");
|
||||
Log.d("NearbyCon java", "onEndpointLost");
|
||||
Map<String, Object> args = new HashMap<>();
|
||||
args.put("endpointId", endpointId);
|
||||
channel.invokeMethod("dis.onEndpointLost", args);
|
||||
|
||||
Reference in New Issue
Block a user