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

The following examples show how to use com.google.android.gms.nearby.connection.Strategy. 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: MainActivity.java    From connectivity-samples with Apache License 2.0 4 votes vote down vote up
/** {@see ConnectionsActivity#getStrategy()} */
@Override
public Strategy getStrategy() {
  return STRATEGY;
}
 
Example #2
Source File: MainActivity.java    From connectivity-samples with Apache License 2.0 4 votes vote down vote up
/** {@see ConnectionsActivity#getStrategy()} */
@Override
public Strategy getStrategy() {
  return STRATEGY;
}
 
Example #3
Source File: NearbyConnectionModule.java    From react-native-google-nearby-connection with MIT License 4 votes vote down vote up
@ReactMethod
protected void startAdvertising(final String endpointName, final String serviceId, final int strategy) {
	mIsAdvertising = true;
	onAdvertisingStarting(endpointName, serviceId);

	Strategy finalStrategy = Strategy.P2P_CLUSTER;
	switch(strategy) {
		case 0: finalStrategy = Strategy.P2P_CLUSTER;
			break;
		case 1: finalStrategy = Strategy.P2P_STAR;
			break;
	}

	final Activity activity = getCurrentActivity();
	final ConnectionsClient clientSingleton = getConnectionsClientSingleton(serviceId);
	final AdvertisingOptions advertisingOptions =  new AdvertisingOptions(finalStrategy);

       permissionsCheck(activity, Arrays.asList(getRequiredPermissions()), new Callable<Void>() {
           @Override
           public Void call() throws Exception {
			clientSingleton
				.startAdvertising(
					endpointName,
					serviceId,
					getConnectionLifecycleCallback(serviceId, "advertised"),
					advertisingOptions
				)
				.addOnSuccessListener(
					new OnSuccessListener<Void>() {
						@Override
						public void onSuccess(Void unusedResult) {
							logV("Now advertising endpoint " + endpointName + " with serviceId " + serviceId);
							onAdvertisingStarted(endpointName, serviceId);
						}
					}
				)
				.addOnFailureListener(
					new OnFailureListener() {
						@Override
						public void onFailure(@NonNull Exception e) {
							ApiException apiException = (ApiException) e;

							mIsAdvertising = false;
							logW("startAdvertising for endpointName "+ endpointName +" serviceId "+ serviceId +" failed.", e);
							onAdvertisingStartFailed(endpointName, serviceId, apiException.getStatusCode());
						}
					}
				);

               return null;
           }
       });
}
 
Example #4
Source File: NearbyConnectionModule.java    From react-native-google-nearby-connection with MIT License 4 votes vote down vote up
@ReactMethod
public void startDiscovering(final String serviceId, final int strategy) {
	mIsDiscovering = true;
	onDiscoveryStarting(serviceId);

	Strategy finalStrategy = Strategy.P2P_CLUSTER;
	switch(strategy) {
		case 0: finalStrategy = Strategy.P2P_CLUSTER;
			break;
		case 1: finalStrategy = Strategy.P2P_STAR;
			break;
	}

	final Activity activity = getCurrentActivity();
	final ConnectionsClient clientSingleton = getConnectionsClientSingleton(serviceId);
	final DiscoveryOptions discoveryOptions = new DiscoveryOptions(finalStrategy);

       permissionsCheck(activity, Arrays.asList(getRequiredPermissions()), new Callable<Void>() {
           @Override
           public Void call() throws Exception {
			clientSingleton.startDiscovery(
				serviceId,
				getEndpointDiscoveryCallback(serviceId),
				discoveryOptions
			).addOnSuccessListener(
				new OnSuccessListener<Void>() {
					@Override
					public void onSuccess(Void unusedResult) {
						logV("Now discovering for serviceId "+ serviceId);
						onDiscoveryStarted(serviceId);
					}
				}
			).addOnFailureListener(
				new OnFailureListener() {
					@Override
					public void onFailure(@NonNull Exception e) {
						ApiException apiException = (ApiException) e;

						mIsDiscovering = false;
						logW("startDiscovering for serviceId "+serviceId+" failed.", e);
						onDiscoveryStartFailed(serviceId, apiException.getStatusCode());
					}
				}
			);

               return null;
           }
       });
}
 
Example #5
Source File: NearbyShareActivity.java    From Zom-Android-XMPP with GNU General Public License v3.0 4 votes vote down vote up
@Override
protected Strategy getStrategy() {
    return STRATEGY;
}
 
Example #6
Source File: MainActivity.java    From codeexamples-android with Eclipse Public License 1.0 4 votes vote down vote up
/** Broadcasts our presence using Nearby Connections so other players can find us. */
private void startAdvertising() {
    // Note: Advertising may fail. To keep this demo simple, we don't handle failures.
    connectionsClient.startAdvertising(
            "mykey", getPackageName(), connectionLifecycleCallback, new AdvertisingOptions(Strategy.P2P_STAR));
}
 
Example #7
Source File: ConnectionsActivity.java    From connectivity-samples with Apache License 2.0 2 votes vote down vote up
/**
 * Returns the strategy we use to connect to other devices. Only devices using the same strategy
 * and service id will appear when discovering. Stragies determine how many incoming and outgoing
 * connections are possible at the same time, as well as how much bandwidth is available for use.
 */
protected abstract Strategy getStrategy();
 
Example #8
Source File: ConnectionsActivity.java    From Zom-Android-XMPP with GNU General Public License v3.0 2 votes vote down vote up
/**
 * Returns the strategy we use to connect to other devices. Only devices using the same strategy
 * and service id will appear when discovering. Stragies determine how many incoming and outgoing
 * connections are possible at the same time, as well as how much bandwidth is available for use.
 */
protected abstract Strategy getStrategy();