在 Android 事物中无法连接到 google API 客户端

Cannot connect to google API client in Android Things

这是我的代码

public class MainActivity extends Activity implements GoogleApiClient.ConnectionCallbacks,GoogleApiClient.OnConnectionFailedListener {

    private GoogleApiClient mGoogleApiClient;
    private String TAG = "app comm";


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        int code = GooglePlayServicesUtil.isGooglePlayServicesAvailable(getApplicationContext());
        if (code == ConnectionResult.SUCCESS) {
            Log.d(TAG, "success ");
            buildGoogleApiClient();
        } else {
            Log.d(TAG, "fail ");
        }

    }

    private void buildGoogleApiClient() {
        mGoogleApiClient = new GoogleApiClient.Builder(this)
                .addApi(Nearby.CONNECTIONS_API).addConnectionCallbacks(this).addOnConnectionFailedListener(this).build();
    }

    @Override
    public void onConnected(@Nullable Bundle bundle) {
        Log.d(TAG,"connected");
    }

    @Override
    public void onConnectionSuspended(int i) {
        Log.d(TAG,"suspended");
    }

    @Override
    public void onConnectionFailed(@NonNull ConnectionResult connectionResult) {
        Log.d(TAG,"failed");
    }

}

我是新手 我 运行 这个程序在 raspberry pi 3 我已经检查过,互联网可以正常工作。 isGoogleServicesAvailable 正在返回 true。 但是 none 调用了重写方法。我不知道我错过了什么。

这是我的日志

Connected to process 8191 on device google-iot_rpi3-192.168.1.2:5555
Capturing and displaying logcat messages from application. This behavior can be disabled in the "Logcat output" section of the "Debugger" settings page.
I/zygote: Late-enabling -Xcheck:jni
W/zygote: Using default instruction set features for ARM CPU variant (generic) using conservative defaults
I/InstantRun: starting instant run server: is main process
V/first log: first raspberry log message
D/app comm: success 
D/vndksupport: Loading /vendor/lib/hw/android.hardware.graphics.mapper@2.0-impl.so from current namespace instead of sphal namespace.

查看您的代码片段,您没有在构建后调用 connect 方法,而是实际启动连接并提供回调的方法。