/** * Begin advertising for Nearby Connections, if possible. */ async void StartAdvertising() { // Discover nearby apps that are advertising with the required service ID. var serviceId = GetString(Resource.String.service_id); Log("startAdvertising " + serviceId); if (!IsConnectedToNetwork()) { Log("startAdvertising: not connected to WiFi network."); return; } // Advertising with an AppIdentifer lets other devices on the network discover // this application and prompt the user to install the application. var appIdentifierList = new List <Android.Gms.Nearby.Connection.AppIdentifier> (); appIdentifierList.Add(new Android.Gms.Nearby.Connection.AppIdentifier(this.PackageName)); var appMetadata = new Android.Gms.Nearby.Connection.AppMetadata(appIdentifierList); // Advertise for Nearby Connections. This will broadcast the service id defined in // AndroidManifest.xml. By passing 'null' for the name, the Nearby Connections API // will construct a default name based on device model such as 'LGE Nexus 5'. string name = null; // TODO: asyncify var result = //await Android.Gms.Nearby.NearbyClass.Connections //.StartAdvertisingAsync( .StartAdvertising( mGoogleApiClient, name, appMetadata, TIMEOUT_ADVERTISE, new MyConnectionRequestListener { ConnectionRequestHandler = OnConnectionRequest }); Log("startAdvertising:onResult:" + result); /* * if (result.Status.IsSuccess) { * Log("startAdvertising:onResult: SUCCESS"); * * UpdateViewVisibility (NearbyConnectionState.Advertising); * } else { * Log("startAdvertising:onResult: FAILURE "); * * // If the user hits 'Advertise' multiple times in the timeout window, * // the error will be STATUS_ALREADY_ADVERTISING * if (result.Status.StatusCode == ConnectionsStatusCodes.StatusAlreadyAdvertising) { * Log("STATUS_ALREADY_ADVERTISING"); * } else { * UpdateViewVisibility (NearbyConnectionState.Ready); * } * } */ }
public static async Task <IConnectionsStartAdvertisingResult> StartAdvertisingAsync(this IConnections api, GoogleApiClient apiClient, string name, Android.Gms.Nearby.Connection.AppMetadata appMetadata, long durationMillis, IConnectionsConnectionRequestListener connectionRequestListener) { return((await api.StartAdvertising(apiClient, name, appMetadata, durationMillis, connectionRequestListener)).JavaCast <IConnectionsStartAdvertisingResult> ()); }