I am working on a react-native application that uses the NearbyConnection API. I don't want the connection to be automatically accepted. The user should be able to accept or decline the connection. I tried the code proposed by Google (code below)
new AlertDialog.Builder(context)
.setTitle("Accept connection to " + info.getEndpointName())
.setMessage("Confirm the code matches on both devices: " + info.getAuthenticationDigits())
.setPositiveButton(
"Accept",
(DialogInterface dialog, int which) ->
// The user confirmed, so we can accept the connection.
Nearby.getConnectionsClient(context)
.acceptConnection(endpointId, payloadCallback))
.setNegativeButton(
"Refuse",
(DialogInterface dialog, int which) ->
// The user canceled, so we should reject the connection.
Nearby.getConnectionsClient(context).rejectConnection(endpointId))
.setIcon(android.R.drawable.ic_dialog_alert)
.show();
but it doesn't work (the application crashes at this level). Is there a way to rewrite this code to be compatible with reat-native? Or is it possible to execute a JS function and get the result in Java?