com.google.android.gms.nearby.connection.ConnectionInfo Java Examples

The following examples show how to use com.google.android.gms.nearby.connection.ConnectionInfo. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: NearbyConnectionModule.java    From react-native-google-nearby-connection with MIT License 6 votes vote down vote up
/**
 * Called when a connection to a nearby advertiser is initiated
 */
private void connectionInitiatedToEndpoint(final String serviceId, final String endpointId, final ConnectionInfo connectionInfo) {
	final Endpoint endpoint = mEndpoints.get(serviceId+"_"+endpointId);

	String authenticationToken = connectionInfo.getAuthenticationToken();
	String endpointName = connectionInfo.getEndpointName();
	Boolean incomingConnection = connectionInfo.isIncomingConnection();

	// Broadcast endpoint discovered
	Intent i = new Intent("com.butchmarshall.reactnative.google.nearby.connection.ConnectionInitiatedToEndpoint");
	Bundle bundle = new Bundle();
	bundle.putString("endpointId", endpointId);
	bundle.putString("endpointName", endpointName);
	bundle.putString("serviceId", serviceId);
	bundle.putString("authenticationToken", authenticationToken);
	bundle.putBoolean("incomingConnection", incomingConnection);
	i.putExtras(bundle);

	final Activity activity = getCurrentActivity();
	activity.sendBroadcast(i);
}
 
Example #2
Source File: RobocarDiscoverer.java    From robocar with Apache License 2.0 6 votes vote down vote up
@Override
protected void onNearbyConnectionInitiated(String endpointId, ConnectionInfo connectionInfo) {
    super.onNearbyConnectionInitiated(endpointId, connectionInfo);
    RobocarConnection connection = mRobocarConnectionLiveData.getValue();
    if (connection != null && connection.endpointMatches(endpointId)) {
        connection.setAuthToken(connectionInfo.getAuthenticationToken());
        if (connection.isAutoConnect()) {
            acceptConnection();
        } else {
            // Wait for something else to call acceptConnection.
            connection.setState(ConnectionState.AUTHENTICATING);
        }
    } else {
        // We didn't request this connection, so reject it.
        rejectConnection(endpointId);
    }
}
 
Example #3
Source File: ConnectionsActivity.java    From connectivity-samples with Apache License 2.0 5 votes vote down vote up
@Override
public void onConnectionInitiated(String endpointId, ConnectionInfo connectionInfo) {
  logD(
      String.format(
          "onConnectionInitiated(endpointId=%s, endpointName=%s)",
          endpointId, connectionInfo.getEndpointName()));
  Endpoint endpoint = new Endpoint(endpointId, connectionInfo.getEndpointName());
  mPendingConnections.put(endpointId, endpoint);
  ConnectionsActivity.this.onConnectionInitiated(endpoint, connectionInfo);
}
 
Example #4
Source File: MainActivity.java    From connectivity-samples with Apache License 2.0 5 votes vote down vote up
@Override
protected void onConnectionInitiated(Endpoint endpoint, ConnectionInfo connectionInfo) {
  // A connection to another device has been initiated! We'll use the auth token, which is the
  // same on both devices, to pick a color to use when we're connected. This way, users can
  // visually see which device they connected with.
  mConnectedColor = COLORS[connectionInfo.getAuthenticationToken().hashCode() % COLORS.length];

  // We accept the connection immediately.
  acceptConnection(endpoint);
}
 
Example #5
Source File: RobocarAdvertiser.java    From robocar with Apache License 2.0 5 votes vote down vote up
@Override
protected void onNearbyConnectionInitiated(final String endpointId,
        ConnectionInfo connectionInfo) {
    super.onNearbyConnectionInitiated(endpointId, connectionInfo);
    if (mCompanionConnectionLiveData.getValue() != null) {
        // We already have a companion trying to connect. Reject this one.
        Nearby.Connections.rejectConnection(mGoogleApiClient, endpointId);
        return;
    }


    DiscovererInfo info = DiscovererInfo.parse(connectionInfo.getEndpointName());
    if (info == null || isNotTheDroidWeAreLookingFor(info)) {
        // Discoverer looks malformed, or doesn't match our previous paired companion.
        Nearby.Connections.rejectConnection(mGoogleApiClient, endpointId);
        return;
    }

    // Store the endpoint and accept.
    CompanionConnection connection = new CompanionConnection(endpointId, info, this);
    connection.setAuthToken(connectionInfo.getAuthenticationToken());
    connection.setState(ConnectionState.AUTH_ACCEPTED);
    mCompanionConnectionLiveData.setValue(connection);

    Nearby.Connections.acceptConnection(mGoogleApiClient, endpointId, mInternalPayloadListener)
            .setResultCallback(new ResultCallback<Status>() {
                @Override
                public void onResult(@NonNull Status status) {
                    if (status.isSuccess()) {
                        Log.d(TAG, "Accepted connection. " + endpointId);
                        // TODO implement a timeout
                    } else {
                        Log.d(TAG, "Accept connection failed." + endpointId);
                        // revert state
                        clearCompanionEndpoint();
                    }
                }
            });
}
 
Example #6
Source File: NearbyShareActivity.java    From Zom-Android-XMPP with GNU General Public License v3.0 5 votes vote down vote up
@Override
protected void onConnectionInitiated(Endpoint endpoint, ConnectionInfo connectionInfo) {
    // A connection to another device has been initiated! We'll use the auth token, which is the
    // same on both devices, to pick a color to use when we're connected. This way, users can
    // visually see which device they connected with.
    //  mConnectedColor = COLORS[connectionInfo.getAuthenticationToken().hashCode() % COLORS.length];
    acceptConnection(endpoint);
    addContact(endpoint.getName());
}
 
Example #7
Source File: ConnectionsActivity.java    From Zom-Android-XMPP with GNU General Public License v3.0 5 votes vote down vote up
@Override
public void onConnectionInitiated(String endpointId, ConnectionInfo connectionInfo) {
  logD(
      String.format(
          "onConnectionInitiated(endpointId=%s, endpointName=%s)",
          endpointId, connectionInfo.getEndpointName()));
  Endpoint endpoint = new Endpoint(endpointId, connectionInfo.getEndpointName());
  mPendingConnections.put(endpointId, endpoint);
  ConnectionsActivity.this.onConnectionInitiated(endpoint, connectionInfo);
}
 
Example #8
Source File: MainActivity.java    From connectivity-samples with Apache License 2.0 4 votes vote down vote up
@Override
protected void onConnectionInitiated(Endpoint endpoint, ConnectionInfo connectionInfo) {
  // A connection to another device has been initiated! We'll accept the connection immediately.
  acceptConnection(endpoint);
}
 
Example #9
Source File: MainActivity.java    From codeexamples-android with Eclipse Public License 1.0 4 votes vote down vote up
@Override
public void onConnectionInitiated(String endpointId, ConnectionInfo connectionInfo) {
    connectionsClient.acceptConnection(endpointId, payloadCallback);
    opponentName = connectionInfo.getEndpointName();
}
 
Example #10
Source File: ConnectionsActivity.java    From connectivity-samples with Apache License 2.0 2 votes vote down vote up
/**
 * Called when a pending connection with a remote endpoint is created. Use {@link ConnectionInfo}
 * for metadata about the connection (like incoming vs outgoing, or the authentication token). If
 * we want to continue with the connection, call {@link #acceptConnection(Endpoint)}. Otherwise,
 * call {@link #rejectConnection(Endpoint)}.
 */
protected void onConnectionInitiated(Endpoint endpoint, ConnectionInfo connectionInfo) {}
 
Example #11
Source File: ConnectionsActivity.java    From Zom-Android-XMPP with GNU General Public License v3.0 2 votes vote down vote up
/**
 * Called when a pending connection with a remote endpoint is created. Use {@link ConnectionInfo}
 * for metadata about the connection (like incoming vs outgoing, or the authentication token). If
 * we want to continue with the connection, call {@link #acceptConnection(Endpoint)}. Otherwise,
 * call {@link #rejectConnection(Endpoint)}.
 */
protected void onConnectionInitiated(Endpoint endpoint, ConnectionInfo connectionInfo) {}
 
Example #12
Source File: NearbyConnectionManager.java    From robocar with Apache License 2.0 votes vote down vote up
protected void onNearbyConnectionInitiated(String endpointId, ConnectionInfo connectionInfo) {}