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


Java ConnectionsStatusCodes类代码示例

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


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

示例1: handleOnConnectionResult

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

示例2: startDiscovering

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

示例3: startAdvertising

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

示例4: sendConnectionRequest

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

示例5: acceptConnectionRequest

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

示例6: onConnectionResult

import com.google.android.gms.nearby.connection.ConnectionsStatusCodes; //导入依赖的package包/类
@Override
public void onConnectionResult(String endpointId, ConnectionResolution result) {
    switch (result.getStatus().getStatusCode()) {
        case ConnectionsStatusCodes.STATUS_OK:
            // We're connected! Can now start sending and receiving data.
            stopDiscovering();
            ConnectedEndPointId = endpointId;
            logthis("Status ok, sending Hi message");
            send("Hi from Discovery");
            break;
        case ConnectionsStatusCodes.STATUS_CONNECTION_REJECTED:
            logthis("Status rejected.  :(");
            // The connection was rejected by one or both sides.
            break;
        case ConnectionsStatusCodes.STATUS_ERROR:
            logthis("Status error.");
            // The connection broke before it was able to be accepted.
            break;
    }
}
 
开发者ID:JimSeker,项目名称:googleplayAPI,代码行数:21,代码来源:DiscoveryFragment.java

示例7: onConnectionResult

import com.google.android.gms.nearby.connection.ConnectionsStatusCodes; //导入依赖的package包/类
@Override
public void onConnectionResult(String endpointId, ConnectionResolution result) {
    logthis("Connection accept :" + endpointId + " result is " + result.toString());

    switch (result.getStatus().getStatusCode()) {
        case ConnectionsStatusCodes.STATUS_OK:
            // We're connected! Can now start sending and receiving data.
            ConnectedEndPointId = endpointId;
            //if we don't then more can be added to conversation, when an List<string> of endpointIds to send to, instead a string.
            // ... .add(endpointId);
            stopAdvertising();  //and comment this out to allow more then one connection.
            logthis("Status ok, sending Hi message");
            send("Hi from Advertiser");
            break;
        case ConnectionsStatusCodes.STATUS_CONNECTION_REJECTED:
            logthis("Status rejected.  :(");
            // The connection was rejected by one or both sides.
            break;
        case ConnectionsStatusCodes.STATUS_ERROR:
            logthis("Status error.");
            // The connection broke before it was able to be accepted.
            break;
    }
}
 
开发者ID:JimSeker,项目名称:googleplayAPI,代码行数:25,代码来源:AdvertiseFragment.java

示例8: startDiscovery

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

示例9: startAdvertising

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

示例10: onConnectionResponse

import com.google.android.gms.nearby.connection.ConnectionsStatusCodes; //导入依赖的package包/类
@Override
public final void onConnectionResponse(String remoteEndpointId, Status status, byte[] bytes) {
    switch (status.getStatusCode()) {
        case ConnectionsStatusCodes.STATUS_OK:
            onNearbyConnectionEndpointConnected(remoteEndpointId);
            break;
        case ConnectionsStatusCodes.STATUS_CONNECTION_REJECTED:
            break;
        case ConnectionsStatusCodes.STATUS_NOT_CONNECTED_TO_ENDPOINT:
            break;
    }
}
 
开发者ID:asadmshah,项目名称:drawnearby,代码行数:13,代码来源:BaseConnection.java

示例11: startDiscovery

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

示例12: startAdvertising

import com.google.android.gms.nearby.connection.ConnectionsStatusCodes; //导入依赖的package包/类
/**
 * Begin advertising for Nearby Connections, if possible.
 */
private void startAdvertising() {
    debugLog("startAdvertising");
    if (!isConnectedToNetwork()) {
        debugLog("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.
    List<AppIdentifier> appIdentifierList = new ArrayList<>();
    appIdentifierList.add(new AppIdentifier(getActivity().getPackageName()));
    AppMetadata appMetadata = new 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'.
    Nearby.Connections.startAdvertising(mGoogleApiClient, null, appMetadata, TIMEOUT_ADVERTISE,
            this).setResultCallback(new ResultCallback<Connections.StartAdvertisingResult>() {
        @Override
        public void onResult(Connections.StartAdvertisingResult result) {
            Log.d(TAG, "startAdvertising:onResult:" + result.getStatus());
            if (result.getStatus().isSuccess()) {
                debugLog("startAdvertising:onResult: SUCCESS");

                updateViewVisibility(STATE_ADVERTISING);
            } else {
                debugLog("startAdvertising:onResult: FAILURE ");

                // If the user hits 'Advertise' multiple times in the timeout window,
                // the error will be STATUS_ALREADY_ADVERTISING
                int statusCode = result.getStatus().getStatusCode();
                if (statusCode == ConnectionsStatusCodes.STATUS_ALREADY_ADVERTISING) {
                    debugLog("STATUS_ALREADY_ADVERTISING");
                } else {
                    updateViewVisibility(STATE_READY);
                }
            }
        }
    });
}
 
开发者ID:ToxicBakery,项目名称:MarshmallowDemo,代码行数:44,代码来源:FragmentNearby.java


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