Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for Tried to send a platform message to Flutter, but FlutterJNI was detached from native C++. Could not send. Channel: nearby_connections. Response ID: 4 #79

Open
wants to merge 16 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
16 commits
Select commit Hold shift + click to select a range
679bae9
Implemented service aware
rahulmaindargi Aug 4, 2024
94fb423
import fix
rahulmaindargi Aug 4, 2024
66be19b
fix for FlutterJNI( 7138): Tried to send a platform message to Flutte…
rahulmaindargi Dec 28, 2024
5c8cd55
fix for FlutterJNI( 7138): Tried to send a platform message to Flutte…
rahulmaindargi Dec 28, 2024
c85feab
fix for FlutterJNI( 7138): Tried to send a platform message to Flutte…
rahulmaindargi Dec 28, 2024
a154404
fix for FlutterJNI( 7138): Tried to send a platform message to Flutte…
rahulmaindargi Dec 28, 2024
3faa08c
fix for FlutterJNI( 7138): Tried to send a platform message to Flutte…
rahulmaindargi Dec 28, 2024
6116558
fix for FlutterJNI( 7138): Tried to send a platform message to Flutte…
rahulmaindargi Dec 29, 2024
497c7d0
fix for FlutterJNI( 7138): Tried to send a platform message to Flutte…
rahulmaindargi Dec 29, 2024
68d6d54
fix for FlutterJNI( 7138): Tried to send a platform message to Flutte…
rahulmaindargi Dec 29, 2024
73f6f08
fix for FlutterJNI( 7138): Tried to send a platform message to Flutte…
rahulmaindargi Jan 5, 2025
ec8c874
fix for FlutterJNI( 7138): Tried to send a platform message to Flutte…
rahulmaindargi Jan 5, 2025
6711693
fix for FlutterJNI( 7138): Tried to send a platform message to Flutte…
rahulmaindargi Jan 5, 2025
1254659
fix for FlutterJNI( 7138): Tried to send a platform message to Flutte…
rahulmaindargi Jan 5, 2025
4be0c94
changes for event channel
rahulmaindargi Jan 7, 2025
de5f20d
changes for event channel
rahulmaindargi Jan 8, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
import io.flutter.plugin.common.MethodChannel.Result;
import io.flutter.plugin.common.PluginRegistry;
import io.flutter.plugin.common.PluginRegistry.Registrar;
import io.flutter.plugin.common.EventChannel;

/**
* NearbyConnectionsPlugin
Expand All @@ -50,8 +51,9 @@ public class NearbyConnectionsPlugin implements MethodCallHandler, FlutterPlugin
private Activity activity;
private static final String SERVICE_ID = "com.pkmnapps.nearby_connections";
private static MethodChannel channel;
private static EventChannel eventChannel;
private static PluginRegistry.Registrar pluginRegistrar;

private static EventChannel.EventSink eventSink;
private NearbyConnectionsPlugin(Activity activity) {
this.activity = activity;
}
Expand All @@ -67,6 +69,18 @@ public static void registerWith(Registrar registrar) {
pluginRegistrar = registrar;
channel = new MethodChannel(registrar.messenger(), "nearby_connections");
channel.setMethodCallHandler(new NearbyConnectionsPlugin(registrar.activity()));
// eventChannel=new EventChannel(flutterEngine.getDartExecutor().getBinaryMessenger(), "nearby_connections/events");
// eventChannel.setStreamHandler(
// new EventChannel.StreamHandler() {
// @Override
// public void onListen(Object arguments, EventChannel.EventSink events) {
// eventSink=events;
// }
// @Override
// public void onCancel(Object arguments) {
// eventSink=null;
// }
// });
}

@Override
Expand Down Expand Up @@ -115,7 +129,7 @@ public void onMethodCall(MethodCall call, final Result result) {
.setStrategy(getStrategy(strategy)).build();

Nearby.getConnectionsClient(activity).startAdvertising(userNickName, serviceId,
advertConnectionLifecycleCallback, advertisingOptions)
advertConnectionLifecycleCallback, advertisingOptions)
.addOnSuccessListener(new OnSuccessListener<Void>() {
@Override
public void onSuccess(Void aVoid) {
Expand Down Expand Up @@ -284,7 +298,9 @@ public void onConnectionInitiated(@NonNull String endpointId, @NonNull Connectio
args.put("endpointName", connectionInfo.getEndpointName());
args.put("authenticationToken", connectionInfo.getAuthenticationToken());
args.put("isIncomingConnection", connectionInfo.isIncomingConnection());
channel.invokeMethod("ad.onConnectionInitiated", args);
// channel.invokeMethod("ad.onConnectionInitiated", args);
args.put("method", "ad.onConnectionInitiated");
eventSink.success(args);
}

@Override
Expand All @@ -310,15 +326,19 @@ public void onConnectionResult(@NonNull String endpointId, @NonNull ConnectionRe
// Unknown status code
}
args.put("statusCode", statusCode);
channel.invokeMethod("ad.onConnectionResult", args);
//channel.invokeMethod("ad.onConnectionResult", args);
args.put("method", "ad.onConnectionResult");
eventSink.success(args);
}

@Override
public void onDisconnected(@NonNull String endpointId) {
Log.d("nearby_connections", "ad.onDisconnected");
Map<String, Object> args = new HashMap<>();
args.put("endpointId", endpointId);
channel.invokeMethod("ad.onDisconnected", args);
//channel.invokeMethod("ad.onDisconnected", args);
args.put("method", "ad.onDisconnected");
eventSink.success(args);
}
};

Expand All @@ -331,7 +351,9 @@ public void onConnectionInitiated(@NonNull String endpointId, @NonNull Connectio
args.put("endpointName", connectionInfo.getEndpointName());
args.put("authenticationToken", connectionInfo.getAuthenticationToken());
args.put("isIncomingConnection", connectionInfo.isIncomingConnection());
channel.invokeMethod("dis.onConnectionInitiated", args);
//channel.invokeMethod("dis.onConnectionInitiated", args);
args.put("method", "dis.onConnectionInitiated");
eventSink.success(args);
}

@Override
Expand All @@ -357,15 +379,19 @@ public void onConnectionResult(@NonNull String endpointId, @NonNull ConnectionRe
// Unknown status code
}
args.put("statusCode", statusCode);
channel.invokeMethod("dis.onConnectionResult", args);
// channel.invokeMethod("dis.onConnectionResult", args);
args.put("method", "dis.onConnectionResult");
eventSink.success(args);
}

@Override
public void onDisconnected(@NonNull String endpointId) {
Log.d("nearby_connections", "dis.onDisconnected");
Map<String, Object> args = new HashMap<>();
args.put("endpointId", endpointId);
channel.invokeMethod("dis.onDisconnected", args);
//channel.invokeMethod("dis.onDisconnected", args);
args.put("method","dis.onDisconnected");
eventSink.success(args);
}
};

Expand All @@ -390,12 +416,14 @@ public void onPayloadReceived(@NonNull String endpointId, @NonNull Payload paylo
}
}

channel.invokeMethod("onPayloadReceived", args);
//channel.invokeMethod("onPayloadReceived", args);
args.put("method","onPayloadReceived");
eventSink.success(args);
}

@Override
public void onPayloadTransferUpdate(@NonNull String endpointId,
@NonNull PayloadTransferUpdate payloadTransferUpdate) {
@NonNull PayloadTransferUpdate payloadTransferUpdate) {
// required for files and streams

Log.d("nearby_connections", "onPayloadTransferUpdate");
Expand All @@ -406,28 +434,34 @@ public void onPayloadTransferUpdate(@NonNull String endpointId,
args.put("bytesTransferred", payloadTransferUpdate.getBytesTransferred());
args.put("totalBytes", payloadTransferUpdate.getTotalBytes());

channel.invokeMethod("onPayloadTransferUpdate", args);
//channel.invokeMethod("onPayloadTransferUpdate", args);
args.put("method","onPayloadTransferUpdate");
eventSink.success(args);
}
};

private final EndpointDiscoveryCallback endpointDiscoveryCallback = new EndpointDiscoveryCallback() {
@Override
public void onEndpointFound(@NonNull String endpointId,
@NonNull DiscoveredEndpointInfo discoveredEndpointInfo) {
@NonNull DiscoveredEndpointInfo discoveredEndpointInfo) {
Log.d("nearby_connections", "onEndpointFound");
Map<String, Object> args = new HashMap<>();
args.put("endpointId", endpointId);
args.put("endpointName", discoveredEndpointInfo.getEndpointName());
args.put("serviceId", discoveredEndpointInfo.getServiceId());
channel.invokeMethod("dis.onEndpointFound", args);
//channel.invokeMethod("dis.onEndpointFound", args);
args.put("method","dis.onEndpointFound");
eventSink.success(args);
}

@Override
public void onEndpointLost(@NonNull String endpointId) {
Log.d("nearby_connections", "onEndpointLost");
Map<String, Object> args = new HashMap<>();
args.put("endpointId", endpointId);
channel.invokeMethod("dis.onEndpointLost", args);
//channel.invokeMethod("dis.onEndpointLost", args);
args.put("method","dis.onEndpointLost");
eventSink.success(args);
}
};

Expand All @@ -448,6 +482,18 @@ private Strategy getStrategy(int strategy) {
public void onAttachedToEngine(@NonNull FlutterPluginBinding binding) {
channel = new MethodChannel(binding.getBinaryMessenger(), "nearby_connections");
channel.setMethodCallHandler(this);
eventChannel=new EventChannel(binding.getFlutterEngine().getDartExecutor().getBinaryMessenger(), "nearby_connections/events");
eventChannel.setStreamHandler(
new EventChannel.StreamHandler() {
@Override
public void onListen(Object arguments, EventChannel.EventSink events) {
eventSink=events;
}
@Override
public void onCancel(Object arguments) {
eventSink=null;
}
});
}

@Override
Expand Down Expand Up @@ -486,4 +532,4 @@ private static void copyStream(InputStream in, OutputStream out) throws IOExcept
out.close();
}
}
}
}
Loading