本文整理汇总了Java中com.google.android.gms.nearby.connection.Connections类的典型用法代码示例。如果您正苦于以下问题:Java Connections类的具体用法?Java Connections怎么用?Java Connections使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Connections类属于com.google.android.gms.nearby.connection包,在下文中一共展示了Connections类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: onStop
import com.google.android.gms.nearby.connection.Connections; //导入依赖的package包/类
@Override
protected void onStop() {
super.onStop();
if (mGoogleApiClient != null && mGoogleApiClient.isConnected()) {
Nearby.Connections.stopAdvertising(mGoogleApiClient);
if (!mRemotePeerEndpoints.isEmpty()) {
Nearby.Connections.sendPayload(mGoogleApiClient, mRemotePeerEndpoints, Payload.fromBytes("Shutting down host".getBytes(Charset.forName("UTF-8"))));
Nearby.Connections.stopAllEndpoints(mGoogleApiClient);
mRemotePeerEndpoints.clear();
}
mGoogleApiClient.disconnect();
}
}
开发者ID:Nilhcem,项目名称:nearby-connections-api-sample-things,代码行数:17,代码来源:MainActivity.java
示例2: disconnect
import com.google.android.gms.nearby.connection.Connections; //导入依赖的package包/类
public void disconnect() {
Timber.d("disconnect");
if (mGoogleApiClient.isConnected()) {
Nearby.Connections.stopAdvertising(mGoogleApiClient);
if (!mRemotePeerEndpoints.isEmpty()) {
Nearby.Connections.sendPayload(mGoogleApiClient,
mRemotePeerEndpoints,
Payload.fromBytes("Shutting down host".getBytes(Charset.forName("UTF-8"))));
Nearby.Connections.stopAllEndpoints(mGoogleApiClient);
mRemotePeerEndpoints.clear();
}
mGoogleApiClient.disconnect();
}
}
开发者ID:leinardi,项目名称:androidthings-kuman-sm9,代码行数:17,代码来源:GoogleApiClientRepository.java
示例3: sendStop
import com.google.android.gms.nearby.connection.Connections; //导入依赖的package包/类
private void sendStop() {
if (!googleApiClient.isConnected()) {
view.showApiNotConnected();
return;
}
Nearby.Connections.sendReliableMessage(googleApiClient, otherEndpointId, toByteArray(-1));
}
开发者ID:riggaroo,项目名称:android-things-distributed-piano,代码行数:9,代码来源:PlayPianoPresenter.java
示例4: onConnectionRequest
import com.google.android.gms.nearby.connection.Connections; //导入依赖的package包/类
@Override
public void onConnectionRequest(final String endpointId, String deviceId, String endpointName, byte[] payload) {
Log.d(TAG, "onConnectionRequest");
Nearby.Connections.acceptConnectionRequest(googleApiClient, endpointId, payload, this)
.setResultCallback(new ResultCallback<Status>() {
@Override
public void onResult(@NonNull Status status) {
if (status.isSuccess()) {
Log.d(TAG, "acceptConnectionRequest: SUCCESS");
} else {
Log.d(TAG, "acceptConnectionRequest: FAILURE");
}
}
});
}
开发者ID:riggaroo,项目名称:android-things-distributed-piano,代码行数:18,代码来源:PianoPresenter.java
示例5: startDiscovering
import com.google.android.gms.nearby.connection.Connections; //导入依赖的package包/类
protected void startDiscovering() {
Nearby.Connections.startDiscovery(connection, serviceId, Connections.DURATION_INDEFINITE, this)
.setResultCallback(new ResultCallback<Status>() {
@Override
public void onResult(@NonNull Status status) {
switch (status.getStatusCode()) {
case ConnectionsStatusCodes.STATUS_OK:
onNearbyConnectionDiscoveringSuccess();
break;
case ConnectionsStatusCodes.STATUS_NETWORK_NOT_CONNECTED:
onNearbyConnectionNetworkNotConnected();
break;
case ConnectionsStatusCodes.STATUS_ALREADY_DISCOVERING:
break;
}
}
});
}
开发者ID:asadmshah,项目名称:drawnearby,代码行数:19,代码来源:BaseConnection.java
示例6: startAdvertising
import com.google.android.gms.nearby.connection.Connections; //导入依赖的package包/类
protected void startAdvertising(String name) {
List<AppIdentifier> appIdentifierList = new ArrayList<>();
appIdentifierList.add(new AppIdentifier(connection.getContext().getPackageName()));
AppMetadata appMetadata = new AppMetadata(appIdentifierList);
Nearby.Connections.startAdvertising(connection, name, appMetadata, Connections.DURATION_INDEFINITE, this)
.setResultCallback(new ResultCallback<Connections.StartAdvertisingResult>() {
@Override
public void onResult(@NonNull Connections.StartAdvertisingResult result) {
switch (result.getStatus().getStatusCode()) {
case ConnectionsStatusCodes.STATUS_OK:
onNearbyConnectionAdvertisingSuccess();
break;
case ConnectionsStatusCodes.STATUS_NETWORK_NOT_CONNECTED:
onNearbyConnectionNetworkNotConnected();
break;
case ConnectionsStatusCodes.STATUS_ALREADY_ADVERTISING:
break;
case ConnectionsStatusCodes.STATUS_ERROR:
onNearbyConnectionError(result.getStatus());
break;
}
}
});
}
开发者ID:asadmshah,项目名称:drawnearby,代码行数:26,代码来源:BaseConnection.java
示例7: sendConnectionRequest
import com.google.android.gms.nearby.connection.Connections; //导入依赖的package包/类
protected void sendConnectionRequest(String remoteEndpointId) {
Nearby.Connections.sendConnectionRequest(connection, null, remoteEndpointId, null, this, this)
.setResultCallback(new ResultCallback<Status>() {
@Override
public void onResult(@NonNull Status status) {
switch (status.getStatusCode()) {
case ConnectionsStatusCodes.STATUS_OK:
break;
case ConnectionsStatusCodes.STATUS_NETWORK_NOT_CONNECTED:
onNearbyConnectionNetworkNotConnected();
break;
case ConnectionsStatusCodes.STATUS_ALREADY_CONNECTED_TO_ENDPOINT:
break;
}
}
});
}
开发者ID:asadmshah,项目名称:drawnearby,代码行数:18,代码来源:BaseConnection.java
示例8: acceptConnectionRequest
import com.google.android.gms.nearby.connection.Connections; //导入依赖的package包/类
protected void acceptConnectionRequest(final String remoteEndpointId) {
Nearby.Connections.acceptConnectionRequest(connection, remoteEndpointId, null, this)
.setResultCallback(new ResultCallback<Status>() {
@Override
public void onResult(@NonNull Status status) {
switch (status.getStatusCode()) {
case ConnectionsStatusCodes.STATUS_OK:
onNearbyConnectionEndpointConnected(remoteEndpointId);
break;
case ConnectionsStatusCodes.STATUS_NETWORK_NOT_CONNECTED:
onNearbyConnectionNetworkNotConnected();
break;
case ConnectionsStatusCodes.STATUS_ALREADY_CONNECTED_TO_ENDPOINT:
break;
}
}
});
}
开发者ID:asadmshah,项目名称:drawnearby,代码行数:19,代码来源:BaseConnection.java
示例9: sendMessage
import com.google.android.gms.nearby.connection.Connections; //导入依赖的package包/类
/**
* Send a reliable message to the connected peer. Takes the contents of the EditText and
* sends the message as a byte[].
*/
private void sendMessage() {
// Sends a reliable message, which is guaranteed to be delivered eventually and to respect
// message ordering from sender to receiver. Nearby.Connections.sendUnreliableMessage
// should be used for high-frequency messages where guaranteed delivery is not required, such
// as showing one player's cursor location to another. Unreliable messages are often
// delivered faster than reliable messages.
String msg = mMessageText.getText().toString();
Nearby.Connections.sendReliableMessage(mGoogleApiClient, mOtherEndpointId, msg.getBytes());
mMessageText.setText(null);
View view = getActivity().getCurrentFocus();
if (view != null) {
InputMethodManager imm = (InputMethodManager) getActivity()
.getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(view.getWindowToken(), 0);
}
}
开发者ID:ToxicBakery,项目名称:MarshmallowDemo,代码行数:24,代码来源:FragmentNearby.java
示例10: startAdvertising
import com.google.android.gms.nearby.connection.Connections; //导入依赖的package包/类
/**
* Begin advertising for Nearby Connections.
*/
public void startAdvertising() {
long NO_TIMEOUT = 0L;
Nearby.Connections.startAdvertising(mGoogleApiClient, null, null,
NO_TIMEOUT, myConnectionRequestListener)
.setResultCallback(new ResultCallback<Connections.StartAdvertisingResult>() {
@Override
public void onResult(Connections.StartAdvertisingResult result) {
if (result.getStatus().isSuccess()) {
Log.d(TAG, "Advertising as " +
result.getLocalEndpointName());
mState = STATE_ADVERTISING;
} else {
Log.w(TAG, "Failed to start advertising: " +
result.getStatus());
mState = STATE_IDLE;
}
}
});
}
开发者ID:playgameservices,项目名称:8bitartist,代码行数:24,代码来源:NearbyClient.java
示例11: startDiscovery
import com.google.android.gms.nearby.connection.Connections; //导入依赖的package包/类
/**
* Begin discovering Nearby Connections.
*
* @param serviceId the ID of advertising services to discover.
*/
public void startDiscovery(String serviceId) {
Nearby.Connections.startDiscovery(mGoogleApiClient, serviceId, 0L,
myEndpointDiscoveryListener)
.setResultCallback(new ResultCallback<Status>() {
@Override
public void onResult(@NonNull Status status) {
if (status.isSuccess()) {
Log.d(TAG, "Started discovery.");
mState = STATE_DISCOVERING;
} else {
Log.w(TAG, "Failed to start discovery: " + status);
mState = STATE_IDLE;
}
}
});
}
开发者ID:playgameservices,项目名称:8bitartist,代码行数:22,代码来源:NearbyClient.java
示例12: disconnect
import com.google.android.gms.nearby.connection.Connections; //导入依赖的package包/类
private void disconnect() {
if( !isConnectedToNetwork() )
return;
if( mIsHost ) {
sendMessage( "Shutting down host" );
Nearby.Connections.stopAdvertising( mGoogleApiClient );
Nearby.Connections.stopAllEndpoints( mGoogleApiClient );
mIsHost = false;
mStatusText.setText( "Not connected" );
mRemotePeerEndpoints.clear();
} else {
if( !mIsConnected || TextUtils.isEmpty( mRemoteHostEndpoint ) ) {
Nearby.Connections.stopDiscovery( mGoogleApiClient, getString( R.string.service_id ) );
return;
}
sendMessage( "Disconnecting" );
Nearby.Connections.disconnectFromEndpoint( mGoogleApiClient, mRemoteHostEndpoint );
mRemoteHostEndpoint = null;
mStatusText.setText( "Disconnected" );
}
mIsConnected = false;
}
开发者ID:tutsplus,项目名称:Android-NearbyMessages,代码行数:26,代码来源:MainActivity.java
示例13: onConnectionRequest
import com.google.android.gms.nearby.connection.Connections; //导入依赖的package包/类
@Override
public void onConnectionRequest(final String remoteEndpointId, final String remoteDeviceId, final String remoteEndpointName, byte[] payload) {
if( mIsHost ) {
Nearby.Connections.acceptConnectionRequest( mGoogleApiClient, remoteEndpointId, payload, this ).setResultCallback(new ResultCallback<Status>() {
@Override
public void onResult(Status status) {
if( status.isSuccess() ) {
if( !mRemotePeerEndpoints.contains( remoteEndpointId ) ) {
mRemotePeerEndpoints.add( remoteEndpointId );
}
getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON);
mMessageAdapter.notifyDataSetChanged();
sendMessage(remoteDeviceId + " connected!");
mSendTextContainer.setVisibility( View.VISIBLE );
}
}
});
} else {
Nearby.Connections.rejectConnectionRequest(mGoogleApiClient, remoteEndpointId );
}
}
开发者ID:tutsplus,项目名称:Android-NearbyMessages,代码行数:25,代码来源:MainActivity.java
示例14: startDiscovery
import com.google.android.gms.nearby.connection.Connections; //导入依赖的package包/类
private void startDiscovery() {
Log.d(TAG, "startDiscovery");
if (!isConnectedToNetwork()) {
Log.d(TAG, "startDiscovery: not connected to WiFi network.");
return;
}
Nearby.Connections.startDiscovery(googleApiClient, serviceId, TIMEOUT_DISCOVER, this)
.setResultCallback(new ResultCallback<Status>() {
@Override
public void onResult(@NonNull Status status) {
if (!isViewAttached()) {
return;
}
if (status.isSuccess()) {
Log.d(TAG, "startDiscovery:onResult: SUCCESS");
} else {
Log.d(TAG, "startDiscovery:onResult: FAILURE");
int statusCode = status.getStatusCode();
if (statusCode == ConnectionsStatusCodes.STATUS_ALREADY_DISCOVERING) {
Log.d(TAG, "STATUS_ALREADY_DISCOVERING");
}
}
}
});
}
开发者ID:riggaroo,项目名称:android-things-distributed-piano,代码行数:28,代码来源:PlayPianoPresenter.java
示例15: sendNote
import com.google.android.gms.nearby.connection.Connections; //导入依赖的package包/类
private void sendNote(final double frequency) {
if (!googleApiClient.isConnected()) {
view.showApiNotConnected();
return;
}
Nearby.Connections.sendReliableMessage(googleApiClient, otherEndpointId, toByteArray(frequency));
}
开发者ID:riggaroo,项目名称:android-things-distributed-piano,代码行数:9,代码来源:PlayPianoPresenter.java
示例16: startAdvertising
import com.google.android.gms.nearby.connection.Connections; //导入依赖的package包/类
private void startAdvertising() {
Log.d(TAG, "startAdvertising");
if (!isConnectedToNetwork()) {
Log.d(TAG, "startAdvertising: not connected to WiFi network.");
return;
}
List<AppIdentifier> appIdentifierList = new ArrayList<>();
appIdentifierList.add(new AppIdentifier(packageName));
AppMetadata appMetadata = new AppMetadata(appIdentifierList);
Nearby.Connections.startAdvertising(googleApiClient, serviceId, appMetadata, 0L, this)
.setResultCallback(new ResultCallback<Connections.StartAdvertisingResult>() {
@Override
public void onResult(@NonNull Connections.StartAdvertisingResult result) {
Log.d(TAG, "startAdvertising:onResult:" + result);
if (result.getStatus().isSuccess()) {
Log.d(TAG, "startAdvertising:onResult: SUCCESS");
} else {
Log.d(TAG, "startAdvertising:onResult: FAILURE ");
int statusCode = result.getStatus().getStatusCode();
if (statusCode == ConnectionsStatusCodes.STATUS_ALREADY_ADVERTISING) {
Log.d(TAG, "STATUS_ALREADY_ADVERTISING");
} else {
Log.d(TAG, "STATE_READY");
}
}
}
});
}
开发者ID:riggaroo,项目名称:android-things-distributed-piano,代码行数:31,代码来源:PianoPresenter.java
示例17: startDiscovery
import com.google.android.gms.nearby.connection.Connections; //导入依赖的package包/类
/**
* Begin discovering devices advertising Nearby Connections, if possible.
*/
private void startDiscovery() {
debugLog("startDiscovery");
if (!isConnectedToNetwork()) {
debugLog("startDiscovery: not connected to WiFi network.");
return;
}
// Discover nearby apps that are advertising with the required service ID.
String serviceId = getString(R.string.service_id);
Nearby.Connections.startDiscovery(mGoogleApiClient, serviceId, TIMEOUT_DISCOVER, this)
.setResultCallback(new ResultCallback<Status>() {
@Override
public void onResult(Status status) {
Log.d(TAG, "startDiscovery:onResult: " + status);
if (status.isSuccess()) {
debugLog("startDiscovery:onResult: SUCCESS");
updateViewVisibility(STATE_DISCOVERING);
} else {
debugLog("startDiscovery:onResult: FAILURE");
// If the user hits 'Discover' multiple times in the timeout window,
// the error will be STATUS_ALREADY_DISCOVERING
int statusCode = status.getStatusCode();
if (statusCode == ConnectionsStatusCodes.STATUS_ALREADY_DISCOVERING) {
debugLog("STATUS_ALREADY_DISCOVERING");
} else {
updateViewVisibility(STATE_READY);
}
}
}
});
}
开发者ID:ToxicBakery,项目名称:MarshmallowDemo,代码行数:37,代码来源:FragmentNearby.java
示例18: sendMessageToHost
import com.google.android.gms.nearby.connection.Connections; //导入依赖的package包/类
/**
* Send a reliable message to the Host from a Client.
*/
public void sendMessageToHost(String message) {
try {
byte[] payload = message.getBytes("UTF-8");
Nearby.Connections.sendReliableMessage(mGoogleApiClient,
mHostId, payload);
} catch (UnsupportedEncodingException e) {
Log.e(TAG, "Cannot encode " + message + " to UTF-8?");
}
}
开发者ID:playgameservices,项目名称:8bitartist,代码行数:13,代码来源:NearbyClient.java
示例19: sendMessageTo
import com.google.android.gms.nearby.connection.Connections; //导入依赖的package包/类
/**
* Send a message to a specific participant.
*
* @param endpointId the endpoint ID of the participant that will
* receive the message.
* @param message String to send as payload.
*/
public void sendMessageTo(String endpointId, String message) {
try {
byte[] payload = message.getBytes("UTF-8");
Log.d(TAG, "Sending message: " + message);
Nearby.Connections.sendReliableMessage(mGoogleApiClient,
endpointId, payload);
} catch (UnsupportedEncodingException e) {
Log.e(TAG, "Cannot encode " + message + " to UTF-8?");
}
}
开发者ID:playgameservices,项目名称:8bitartist,代码行数:19,代码来源:NearbyClient.java
示例20: connectTo
import com.google.android.gms.nearby.connection.Connections; //导入依赖的package包/类
/**
* Send a connection request to a remote endpoint. If the request is successful, notify the
* listener and add the connection to the Set. Otherwise, show an error Toast.
*
* @param endpointId the endpointID to connect to.
* @param endpointName the name of the endpoint to connect to.
*/
private void connectTo(final String endpointId,
final String endpointName) {
Log.d(TAG, "connectTo:" + endpointId);
Nearby.Connections.sendConnectionRequest(mGoogleApiClient, null,
endpointId, null,
new Connections.ConnectionResponseCallback() {
@Override
public void onConnectionResponse(String remoteEndpointId, Status status,
byte[] payload) {
Log.d(TAG, "onConnectionResponse:" +
remoteEndpointId + ":" + status);
if (status.isSuccess()) {
// Connection successful, notify listener
Toast.makeText(mContext, "Connected to: " + endpointName,
Toast.LENGTH_SHORT).show();
mHostId = remoteEndpointId;
mConnectedClients.put(remoteEndpointId,
new DrawingParticipant(
remoteEndpointId, endpointName));
mListener.onConnectedToEndpoint(mHostId,
endpointName);
} else {
// Connection not successful, show error
Toast.makeText(mContext, "Error: failed to connect.",
Toast.LENGTH_SHORT).show();
}
}
}, this);
}
开发者ID:playgameservices,项目名称:8bitartist,代码行数:38,代码来源:NearbyClient.java
注:本文中的com.google.android.gms.nearby.connection.Connections类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论