无法连接Android内容中的Google API客户端

时间:2017-12-11 07:52:57

标签: raspberry-pi3 google-api-client 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。 但没有一个覆盖方法被调用。我不知道我错过了什么。

这是我的日志

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.

1 个答案:

答案 0 :(得分:1)

查看您的代码段,在构建代码片段后,您不会调用connect方法,这实际上是启动连接并进行回调。