当前位置: 首页>>代码示例>>Java>>正文


Java Nearby类代码示例

本文整理汇总了Java中com.google.android.gms.nearby.Nearby的典型用法代码示例。如果您正苦于以下问题:Java Nearby类的具体用法?Java Nearby怎么用?Java Nearby使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


Nearby类属于com.google.android.gms.nearby包,在下文中一共展示了Nearby类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: onStop

import com.google.android.gms.nearby.Nearby; //导入依赖的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: onStop

import com.google.android.gms.nearby.Nearby; //导入依赖的package包/类
@Override
protected void onStop() {
    super.onStop();
    log("onStop: disconnect");

    if (mGoogleApiClient.isConnected()) {
        if (!mIsConnected || TextUtils.isEmpty(mRemoteHostEndpoint)) {
            Nearby.Connections.stopDiscovery(mGoogleApiClient);
            return;
        }
        sendMessage("Client disconnecting");
        Nearby.Connections.disconnectFromEndpoint(mGoogleApiClient, mRemoteHostEndpoint);
        mRemoteHostEndpoint = null;
        mIsConnected = false;

        mGoogleApiClient.disconnect();
    }
}
 
开发者ID:Nilhcem,项目名称:nearby-connections-api-sample-things,代码行数:19,代码来源:MainActivity.java

示例3: nearbySubscribe

import com.google.android.gms.nearby.Nearby; //导入依赖的package包/类
private void nearbySubscribe() {
    SubscribeOptions options = new SubscribeOptions.Builder()
            .setStrategy(PUB_SUB_STRATEGY)
            .setCallback(new SubscribeCallback() {
                @Override
                public void onExpired() {
                    super.onExpired();
                    Log.i(TAG, "No longer subscribing");
                }
            }).build();

    Log.i(TAG, "Subscribing.");
    Nearby.Messages.subscribe(mGoogleApiClient, mMessageListener, options)
            .setResultCallback(new ResultCallback<Status>() {
                @Override
                public void onResult(@NonNull Status status) {
                    if (status.isSuccess()) {
                        Log.i(TAG, "Subscribed successfully.");
                        emitSubscription("subscribe.onResult",  "Subscribed successfully.");
                    } else {
                        Log.i(TAG, "Could not subscribe, status = " + status);
                        emitSubscription("subscribe.onResultErr",  "Could not subscribe, status = " + status);
                    }
                }
            });
}
 
开发者ID:miguelespinoza,项目名称:react-native-nearby,代码行数:27,代码来源:NearbyModule.java

示例4: onConnected

import com.google.android.gms.nearby.Nearby; //导入依赖的package包/类
@Override
protected void onConnected() {
    PendingResult<Status> pendingResult = null;
    String actionStr = null;
    if (mAction == SUBSCRIBE) {
        pendingResult = Nearby.Messages.subscribe(
                getGoogleApiClient(), createNearbySubscribeIntent(), createSubscribeOptions());
        actionStr = "background subscribe";
    } else {
        pendingResult = Nearby.Messages.unsubscribe(
                getGoogleApiClient(), createNearbySubscribeIntent());
        actionStr = "background unsubscribe";
    }
    pendingResult.setResultCallback(new SimpleResultCallback(actionStr) {
        @Override
        public void onResult(final Status status) {
            super.onResult(status);
            disconnect();
            if (mCallback != null) {
                mCallback.run();
            }
        }
    });
}
 
开发者ID:rkshuai,项目名称:chromium-for-android-56-debug-video,代码行数:25,代码来源:NearbyBackgroundSubscription.java

示例5: setupGoogleApiClient

import com.google.android.gms.nearby.Nearby; //导入依赖的package包/类
private void setupGoogleApiClient() {
    mGoogleApiClient = new GoogleApiClient.Builder(mApplication)
            .addConnectionCallbacks(new GoogleApiClient.ConnectionCallbacks() {
                @Override
                public void onConnected(@Nullable Bundle bundle) {
                    Timber.d("onConnected: advertises on the network as the host");
                    startNearbyConnectionsAdvertising();
                }

                @Override
                public void onConnectionSuspended(int cause) {
                    Timber.d("onConnectionSuspended: %s", cause);
                    mGoogleApiClient.reconnect();
                }
            })
            .addOnConnectionFailedListener(connectionResult -> Timber.e("onConnectionFailed: %s", connectionResult))
            .addApi(Nearby.CONNECTIONS_API)
            .build();
}
 
开发者ID:leinardi,项目名称:androidthings-kuman-sm9,代码行数:20,代码来源:GoogleApiClientRepository.java

示例6: disconnect

import com.google.android.gms.nearby.Nearby; //导入依赖的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

示例7: setupGoogleApiClient

import com.google.android.gms.nearby.Nearby; //导入依赖的package包/类
private void setupGoogleApiClient() {
    mGoogleApiClient = new GoogleApiClient.Builder(mApplication)
            .addConnectionCallbacks(new GoogleApiClient.ConnectionCallbacks() {
                @Override
                public void onConnected(@Nullable Bundle connectionHint) {
                    startNearbyConnectionsDiscovery();
                }

                @Override
                public void onConnectionSuspended(int cause) {
                    Timber.d("onConnectionSuspended: %s", cause);
                    // Try to re-connect
                    mGoogleApiClient.reconnect();
                }
            })
            .addOnConnectionFailedListener(connectionResult -> {
                Timber.d("onConnectionFailed: " + connectionResult.getErrorCode() + "\n" +
                        connectionResult.getErrorMessage());
                updateConnectionStatus(DISCONNECTED, R.string.connection_info_google_api_connection_failed,
                        connectionResult.getErrorCode(), connectionResult.getErrorMessage());
            })
            .addApi(Nearby.CONNECTIONS_API)
            .build();
}
 
开发者ID:leinardi,项目名称:androidthings-kuman-sm9,代码行数:25,代码来源:GoogleApiClientRepository.java

示例8: handleOnConnectionResult

import com.google.android.gms.nearby.Nearby; //导入依赖的package包/类
private void handleOnConnectionResult(String endpointId, ConnectionResolution resolution) {
    Timber.d("onConnectionResult:" + endpointId + ":" + resolution.getStatus());
    if (resolution.getStatus().isSuccess()) {
        Timber.d("Connected successfully");
        Nearby.Connections.stopDiscovery(mGoogleApiClient);
        mRemoteHostEndpoint = endpointId;
        updateConnectionStatus(CONNECTED, R.string.connection_info_connected);
    } else {
        if (resolution.getStatus().getStatusCode() == ConnectionsStatusCodes.STATUS_CONNECTION_REJECTED) {
            Timber.d("The connection was rejected by one or both sides");
        } else {
            Timber.d("Connection to " + endpointId + " failed. Code: "
                    + resolution.getStatus().getStatusCode());
        }
        updateConnectionStatus(DISCONNECTED, R.string.connection_info_discovery_failed,
                resolution.getStatus().getStatusCode(),
                resolution.getStatus().getStatusMessage());
    }
}
 
开发者ID:leinardi,项目名称:androidthings-kuman-sm9,代码行数:20,代码来源:GoogleApiClientRepository.java

示例9: sendStop

import com.google.android.gms.nearby.Nearby; //导入依赖的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

示例10: onConnectionRequest

import com.google.android.gms.nearby.Nearby; //导入依赖的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

示例11: startDiscovering

import com.google.android.gms.nearby.Nearby; //导入依赖的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

示例12: startAdvertising

import com.google.android.gms.nearby.Nearby; //导入依赖的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

示例13: sendConnectionRequest

import com.google.android.gms.nearby.Nearby; //导入依赖的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

示例14: acceptConnectionRequest

import com.google.android.gms.nearby.Nearby; //导入依赖的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

示例15: onStart

import com.google.android.gms.nearby.Nearby; //导入依赖的package包/类
@Override
public void onStart() {
    super.onStart();

    if (mGoogleApiClient == null) {
        LogUtils.LOGE("***> fragment onStart", "here");
        mActivity.getPreferences(Context.MODE_PRIVATE)
                .registerOnSharedPreferenceChangeListener(mSharedPreferenceChangeListener);

        mGoogleApiClient = new GoogleApiClient.Builder(mActivity)
                .addApi(Nearby.MESSAGES_API)
                .addConnectionCallbacks(mConnectionCallbacks)
                .addOnConnectionFailedListener(mConnectionFailedListener)
                .build();
        mGoogleApiClient.connect();
    }
}
 
开发者ID:kyleparker,项目名称:io16experiment-master,代码行数:18,代码来源:MessageFragment.java


注:本文中的com.google.android.gms.nearby.Nearby类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。