Android ActivityRecognition java.lang.NullPointerException: Appropriate Api was not requested

后端 未结 1 570
南方客
南方客 2021-01-18 05:02

I\'m attempting to follow Google\'s Activity Recognition example.

In the example they start the activity recognition when you click a button, however I\'d like to ju

1条回答
  •  栀梦
    栀梦 (楼主)
    2021-01-18 05:17

    The problem ended up that I was adding the LocationServices.API to the Google API Client, but I wasn't adding ActivityRecognition.API. After I updated my call to this, it worked:

    protected synchronized void buildGoogleApiClient() {
            mGoogleApiClient = new GoogleApiClient.Builder(getActivity())
                    .addConnectionCallbacks(this)
                    .addOnConnectionFailedListener(this)
                    .addApi(LocationServices.API)
                    .addApi(ActivityRecognition.API)
                    .build();
        }
    

    0 讨论(0)
提交回复
热议问题