0

I am using the Google Snapshot API in Android.

I use this code to get the user's activity and store it to Firebase.

//Get user's current activity
private void myCurrentActivity(final String timestamp) {
    if (checkPermission()) {
        Awareness.SnapshotApi.getDetectedActivity(mGoogleApiClient)
                .setResultCallback(new ResultCallback<DetectedActivityResult>() {
                    @Override
                    public void onResult(@NonNull DetectedActivityResult detectedActivityResult) {
                        if (detectedActivityResult.getStatus().isSuccess()) {
                            Log.d(TAG, "myCurrentActivity - SUCCESS");
                            ActivityRecognitionResult activityRecognitionResult = detectedActivityResult.getActivityRecognitionResult();
                            databaseReference.child(getUID(getApplicationContext(), "myCurrentActivity")).child(timestamp).child("activity").setValue(getActivityString(activityRecognitionResult.getMostProbableActivity().getType()));
                            Log.d(TAG, "Most Propable Activity : " + getActivityString(activityRecognitionResult.getMostProbableActivity().getType()));
                        } else {
                            Log.d(TAG, "myCurrentActivity - FAILURE");
                            databaseReference.child(getUID(getApplicationContext(), "myCurrentActivity")).child(timestamp).child("activity").setValue("null");
                        }
                    }
                });
    }
}

The problem is that the onResult function is never executed when i run it.

Do you have any ideas what may cause this ?

Thank you.

EDIT: I just ran it in the emulator and it's working without problems. Is it possible that this has something to do with my device ?

Michalis G.
  • 21
  • 1
  • 6
  • Have you tried checking if `checkPermission()` is returning true? – Rosário Pereira Fernandes Feb 25 '18 at 22:05
  • Yes of course. In the debugging i saw that it executes the .setResultCallback line but it never executes the onResult method. But i don't understand why, the code i use it's almost the same as google's official docs – Michalis G. Feb 25 '18 at 22:24
  • Don't know why it's not working on the device. If this is new development, consider using the [SnapshotClient](https://developers.google.com/android/reference/com/google/android/gms/awareness/SnapshotClient) instead of the deprecated [SnapshotApi](https://developers.google.com/android/reference/com/google/android/gms/awareness/SnapshotApi). `SnapshotClient` saves you the mess of managing a `GoogleApiClient`. – Bob Snyder Feb 25 '18 at 22:41
  • Check that your device has a version of Google Play services installed that is compatible with the Google libs you build with. Look in logcat during app initialization for this message: `W/GooglePlayServicesUtil: Google Play services out of date`. – Bob Snyder Feb 25 '18 at 22:44
  • Thanks for your comment, no my Google Play Services are fine. – Michalis G. Feb 26 '18 at 08:43

0 Answers0