目录

Awareness Kit Manual Conversion Guide

Preparations

If you want your app to support Awareness Kit, complete the integration preparation by referring to Preparations.

API in the BeaconStateResult Class

HMS no longer supports the Google API getBeaconState() in the BeaconStateResult class.

Type

Google API in the BeaconStateResult Class

Method

BeaconStateResult.getBeaconState()

You need to use the getBeaconStatus() API in the BeaconStatusResponse class of HMS to replace this API.

Google API

To HMS API

Add HMS API

BeaconStateResult.getBeaconState()

BeaconStatusResponse.getBeaconStatus()

BeaconStateResponse.getBeaconState()

Google API implementation method of the getBeaconState() API in the BeaconStateResult class:
GoogleApiClient mGoogleApiClient;
mGoogleApiClient = new GoogleApiClient.Builder(this).addApi(Awareness.API).build();
mGoogleApiClient.connect();
// Initiate a request.
Awareness.SnapshotApi.getBeaconState(mGoogleApiClient, BEACON_TYPE_FILTERS).setResultCallback(new ResultCallback<BeaconStateResult>() {
    @Override
    public void onResult(@NonNull BeaconStateResult beaconStateResult) {
        // Obtain the result.
        if (beaconStateResult.getStatus().isSuccess()) {
            BeaconState beaconState = beaconStateResult.getBeaconState();
             }
        }
});

To HMS API method for the getBeaconState() API in the BeaconStateResult class:

// Initiate a request.
Awareness.getCaptureClient(this).getBeaconStatus(BEACON_TYPE_FILTERS).addOnSuccessListener(new OnSuccessListener<BeaconStatusResponse>() {
    @Override
    public void onSuccess(BeaconStatusResponse beaconStatusResponse) {
        // Obtain the result.
        BeaconStatus beaconStatus = beaconStatusResponse.getBeaconStatus();
        }
});

Add HMS API method for the getBeaconState() API in the BeaconStateResult class:

Awareness.getSnapshotClient(this).getBeaconState(BEACON_TYPE_FILTERS).addOnSuccessListener(new OnSuccessListener<BeaconStateResponse>() {
        @Override
    public void onSuccess(BeaconStateResponse param0) {
            // Obtain the result.
        BeaconState beaconState = param0.getBeaconState();
        }
});

API in the DetectedActivityResult/DetectedActivityResponse Class

HMS no longer supports the Google API getActivityRecognitionResult() in the DetectedActivityResult class.

Type

Google API in the DetectedActivityResult Class

Method

DetectedActivityResult.getActivityRecognitionResult()

You need to use the getBehaviorStatus() API in the BehaviorResponse class of HMS to replace this API.

Google API

To HMS API

Add HMS API

DetectedActivityResult.getActivityRecognitionResult()

BehaviorResponse.getBehaviorStatus()

DetectedActivityResponse.getActivityRecognitionResult()

Google API implementation method of the getActivityRecognitionResult() API in the DetectedActivityResult class:

GoogleApiClient mGoogleApiClient;
mGoogleApiClient = new GoogleApiClient.Builder(this).addApi(Awareness.API).build();
mGoogleApiClient.connect();
// Initiate a request.
Awareness.SnapshotApi.getDetectedActivity(mGoogleApiClient).setResultCallback(new ResultCallback<DetectedActivityResult>() {
    @Override
    public void onResult(@NonNull DetectedActivityResult detectedActivityResult) {
        // Obtain the result.
        if (detectedActivityResult.getStatus().isSuccess()) {
            ActivityRecognitionResult activityRecognitionResult = detectedActivityResult.getActivityRecognitionResult();
            long time = activityRecognitionResult.getTime();
            long elapsedTime = activityRecognitionResult.getElapsedRealtimeMillis();
            DetectedActivity detectedActivity = activityRecognitionResult.getMostProbableActivity();
            List<DetectedActivity> detectedActivities = activityRecognitionResult.getProbableActivities();
       }
   }
});

To HMS API method for the getActivityRecognitionResult() API in the DetectedActivityResult class:

// Initiate a request.
Awareness.getCaptureClient(this).getBehavior().addOnSuccessListener(new OnSuccessListener<BehaviorResponse>() {
    @Override
    public void onSuccess(BehaviorResponse behaviorResponse) {
        // Obtain the result.
        BehaviorStatus behaviorStatus = behaviorResponse.getBehaviorStatus();
        long time = behaviorStatus.getTime();
        long elapsedTime = behaviorStatus.getElapsedRealtimeMillis();
        DetectedBehavior detectedBehavior = behaviorStatus.getMostLikelyBehavior();
        List<DetectedBehavior> detectedBehaviors = behaviorStatus.getProbableBehavior();
    }
});

Add HMS API method for the getActivityRecognitionResult() API in the DetectedActivityResult class:

// Initiate a request.
Awareness.getSnapshotClient(this).getDetectedActivity().addOnSuccessListener(new OnSuccessListener<DetectedActivityResponse>() {
    @Override
    public void onSuccess(DetectedActivityResponse param0) {
        // Obtain the result.
        ActivityRecognitionResult activityRecognitionResult = param0.getActivityRecognitionResult();
    }
});

The Google API getActivityRecognitionResult() in the DetectedActivityResponse class cannot be automatically converted in the To HMS API scenario. You need to manually convert the API.

Type

Google API in the DetectedActivityResponse Class

Method

DetectedActivityResponse.getActivityRecognitionResult()

Some methods of Awareness are the same as those of Location. When the To HMS API tool is used for conversion, the classes, methods, and constants of Location are converted. You need to manually convert them into the corresponding classes, methods, and constants of Awareness. The following table lists the comparison between the classes, methods, and constants that need to be converted for Location and Awareness.

Google API implementation method of the getActivityRecognitionResult() API in the DetectedActivityResponse class:

// Initiate a request.
Awareness.getSnapshotClient(this).getDetectedActivity().addOnSuccessListener(new OnSuccessListener<DetectedActivityResponse>() {
    @Override
    public void onSuccess(DetectedActivityResponse detectedActivityResponse) {
        // Obtain the result.
        ActivityRecognitionResult activityRecognitionResult = detectedActivityResponse.getActivityRecognitionResult();
        long time = activityRecognitionResult.getTime();
        long elapsedTime = activityRecognitionResult.getElapsedRealtimeMillis();
        DetectedActivity detectedActivity = activityRecognitionResult.getMostProbableActivity();
        List<DetectedActivity> detectedActivities = activityRecognitionResult.getProbableActivities();
        int type = detectedActivity.getType();
        int confidence = detectedActivity.getConfidence();
    }
});  

To HMS API method for the getActivityRecognitionResult() API in the DetectedActivityResponse class:

// Initiate a request.
Awareness.getCaptureClient(this).getBehavior().addOnSuccessListener(new OnSuccessListener<BehaviorResponse>() {
    @Override
    public void onSuccess(BehaviorResponse behaviorResponse) {
        // Obtain the result.
        BehaviorStatus behaviorStatus = behaviorResponse.getBehaviorStatus();
        long time = behaviorStatus.getTime();
        long elapsedTime = behaviorStatus.getElapsedRealtimeMillis();
        DetectedBehavior detectedBehavior = behaviorStatus.getMostLikelyBehavior();
        List<DetectedBehavior> detectedBehaviors = behaviorStatus.getProbableBehavior();
        //  This type should match BehaviorBarrier
        int type = detectedBehavior.getType();
        int confidence = detectedBehavior.getConfidence();
    }
});

API in the FenceQueryResult Class

HMS no longer supports the Google API getFenceStateMap() in the FenceQueryResult class.

Type

Google API in the FenceQueryResult Class

Method

FenceQueryResult.getFenceStateMap()

You need to use the getBarrierStatusMap() API in the BarrierQueryResponse class of HMS to replace this API.

Google API

To HMS API

Add HMS API

FenceQueryResult.getFenceStateMap()

BarrierQueryResponse.getBarrierStatusMap()

FenceQueryResponse.getFenceStateMap()

Google API implementation method of the getFenceStateMap() API in the FenceQueryResult class:

GoogleApiClient mGoogleApiClient;
mGoogleApiClient = new GoogleApiClient.Builder(this).addApi(Awareness.API).build();
mGoogleApiClient.connect();
// Build a request body.
FenceQueryRequest fenceQueryRequest = FenceQueryRequest.all();
// Initiate a request.
Awareness.FenceApi.queryFences(mGoogleApiClient, fenceQueryRequest).setResultCallback(new ResultCallback<FenceQueryResult>() {
    // Obtain the result.
    @Override
    public void onResult(FenceQueryResult fenceQueryResult) {
        for (String key : fenceQueryResult.getFenceStateMap().getFenceKeys()) {
            FenceState fenceStatus = fenceQueryResult.getFenceStateMap().getFenceState(key);
          }
    }
});

To HMS API method for the getFenceStateMap() API in the FenceQueryResult class:

// Build a request body.
BarrierQueryRequest barrierQueryRequest = BarrierQueryRequest.all();
// Initiate a request.
Awareness.getBarrierClient(this).queryBarriers(barrierQueryRequest).addOnSuccessListener(new OnSuccessListener<BarrierQueryResponse>() {
    @Override
    // Obtain the result.
    public void onSuccess(BarrierQueryResponse barrierQueryResponse) {
        for (String key : barrierQueryResponse.getBarrierStatusMap().getBarrierLabels()) {
            BarrierStatus barrierStatus = barrierQueryResponse.getBarrierStatusMap().getBarrierStatus(key);
        }
    }
});

Add HMS API method for the getFenceStateMap() API in the FenceQueryResult class:

// Build a request body.
FenceQueryRequest fenceQueryRequest = FenceQueryRequest.all();
// Initiate a request.
Awareness.getFenceClient(this).queryFences(fenceQueryRequest).addOnSuccessListener(new OnSuccessListener<FenceQueryResponse>() {
    @Override
    public void onSuccess(FenceQueryResponse param0) {
        // Obtain the result.
        for (String key : param0.getFenceStateMap().getFenceKeys()) {
            FenceState fenceState = param0.getFenceStateMap().getFenceState(key);
        }
    }
});

API in the HeadphoneStateResult Class

HMS no longer supports the Google API getHeadphoneState() in the HeadphoneStateResult class.

Type

Google API

Method

HeadphoneStateResult.getHeadphoneState()

You need to use the getHeadsetStatus() API in the HeadsetStatusResponse class of HMS to replace this API.

Google API

To HMS API

Add HMS API

HeadphoneStateResult.getHeadphoneState()

HeadsetStatusResponse.getHeadsetStatus

HeadphoneStateResponse.getHeadphoneState

Google API implementation method of the getHeadphoneState() API in the HeadphoneStateResult class:

GoogleApiClient mGoogleApiClient;
mGoogleApiClient = new GoogleApiClient.Builder(this).addApi(Awareness.API).build();
mGoogleApiClient.connect();
// Initiate a request.
Awareness.SnapshotApi.getHeadphoneState(mGoogleApiClient).setResultCallback(new ResultCallback<HeadphoneStateResult>() {
    @Override
    public void onResult(@NonNull HeadphoneStateResult headphoneStateResult) {
        // Obtain the result.
        if (headphoneStateResult.getStatus().isSuccess()) {
            HeadphoneState headphoneState = headphoneStateResult.getHeadphoneState();
        }
   }
});

To HMS API method for the getHeadphoneState() API in the HeadphoneStateResult class:

// Initiate a request.
Awareness.getCaptureClient(this).getHeadsetStatus().addOnSuccessListener(new OnSuccessListener<HeadsetStatusResponse>() {
    @Override
    public void onSuccess(HeadsetStatusResponse headsetStatusResponse) {
        // Obtain the result.
        HeadsetStatus headsetStatus = headsetStatusResponse.getHeadsetStatus();
    }
});

Add HMS API method for the getHeadphoneState() API in the HeadphoneStateResult class:

// Initiate a request.
Awareness.getSnapshotClient(this).getHeadphoneState().addOnSuccessListener(new OnSuccessListener<HeadphoneStateResponse>() {
    @Override
    public void onSuccess(HeadphoneStateResponse param0) {
        // Obtain the result.
        HeadphoneState headphoneState = param0.getHeadphoneState();
    }
});

API in the LocationResult Class

HMS no longer supports the Google API getLocation() in the LocationResult class.

Type

Google API in the LocationResult Class

Method

LocationResult.getLocation()

You need to use the getLocation() API in the LocationResponse class of HMS to replace this API.

Google API

To HMS API

Add HMS API

LocationResult.getLocation()

LocationResponse.getLocation()

LocationResponse.getLocation()

Google API implementation method of the getLocation() API in the LocationResult class:

GoogleApiClient mGoogleApiClient;
mGoogleApiClient = new GoogleApiClient.Builder(this).addApi(Awareness.API).build();
mGoogleApiClient.connect();
// Initiate a request.
Awareness.SnapshotApi.getLocation(mGoogleApiClient).setResultCallback(new ResultCallback<LocationResult>() {
    @Override
    public void onResult(@NonNull LocationResult locationResult) {
        // Obtain the result.
        if (locationResult.getStatus().isSuccess()) {
            Location location = locationResult.getLocation();
        }
    }
});

To HMS API method for the getLocation() API in the LocationResult class:

// Initiate a request.
Awareness.getCaptureClient(this).getLocation().addOnSuccessListener(new OnSuccessListener<LocationResponse>() {
    @Override
    public void onSuccess(LocationResponse locationResponse) {
    // Obtain the result.
        Location location = locationResponse.getLocation();
    }
});

Add HMS API method for the getLocation() API in the LocationResult class:

// Initiate a request.
Awareness.getSnapshotClient(this).getLocation().addOnSuccessListener(new OnSuccessListener<LocationResponse>() {
    @Override
    public void onSuccess(LocationResponse param0) {
        // Obtain the result.
        Location location = param0.getLocation();
    }
});

API in the TimeIntervalsResult Class

HMS no longer supports the Google API getTimeIntervals() in the TimeIntervalsResult class.

Type

Google API in the TimeIntervalsResult Class

Method

TimeIntervalsResult.getTimeIntervals()

You need to use the getTimeCategories() API in the TimeCategoriesResponse class of HMS to replace this API.

Google API

To HMS API

Add HMS API

TimeIntervalsResult.getTimeIntervals()

TimeCategoriesResponse.getTimeCategories()

TimeIntervalsResponse.getTimeIntervals()

Google API implementation method of the getTimeIntervals() API in the TimeIntervalsResult class:

GoogleApiClient mGoogleApiClient;
mGoogleApiClient = new GoogleApiClient.Builder(this).addApi(Awareness.API).build();
mGoogleApiClient.connect();
// Initiate a request.
Awareness.SnapshotApi.getTimeIntervals(mGoogleApiClient).setResultCallback(new ResultCallback<TimeIntervalsResult>() {
    @Override
    public void onResult(@NonNull TimeIntervalsResult timeIntervalsResult) {
        // Obtain the result.
        if (timeIntervalsResult.getStatus().isSuccess()) {
            TimeIntervals timeIntervals = timeIntervalsResult.getTimeIntervals();
         }
     }
});

To HMS API method for the getTimeIntervals() API in the TimeIntervalsResult class:

// Initiate a request.
Awareness.getCaptureClient(this).getTimeCategories().addOnSuccessListener(new OnSuccessListener<TimeCategoriesResponse>() {
    @Override
    public void onSuccess(TimeCategoriesResponse timeCategoriesResponse) {
        // Obtain the result.
        TimeCategories timeCategories = timeCategoriesResponse.getTimeCategories();
    }
});

Add HMS API method for the getTimeIntervals() API in the TimeIntervalsResult class:

// Initiate a request.
Awareness.getSnapshotClient(this).getTimeIntervals().addOnSuccessListener(new OnSuccessListener<TimeIntervalsResponse>() {
    @Override
    public void onSuccess(TimeIntervalsResponse param0) {
        // Obtain the result.
        TimeIntervals timeIntervals = param0.getTimeIntervals();
    }
});

APIs and Constants Not Provided by HMS

The following Google API methods and constants have been deprecated in the latest HMS APIs.

Type

Deprecated Google API

To HMS API

Add HMS API

Attribute

Awareness.Api

Not provided

Not provided

Method

SnapshotApi.getPlaces(GoogleApiClient)

Not provided

Not provided

Method

SnapshotApi.getWeather(GoogleApiClient)

Not provided

Not provided

Method

SnapshotClient.getPlaces()

Not provided

Not provided

Method

SnapshotClient.getWeather()

Not provided

Not provided

Method

PlacesResponse.getPlaceLikelihoods()

Not provided

Not provided

Method

PlacesResult.getPlaceLikelihoods()

Not provided

Not provided

Method

WeatherResponse.getWeather()

Not provided

Not provided

Method

WeatherResult.getWeather()

Not provided

Not provided

Method

Weather.getConditions()

Not provided

Not provided

Method

Weather.getDewPoint(int)

Not provided

Not provided

Method

Weather.getFeelsLikeTemperature(int)

Not provided

Not provided

Method

Weather.getHumidity()

Not provided

Not provided

Method

Weather.getTemperature(int)

Not provided

Not provided

Constant

Weather.CELSIUS

Not provided

Not provided

Constant

Weather.CONDITION_CLEAR

Not provided

Not provided

Constant

Weather.CONDITION_CLOUDY

Not provided

Not provided

Constant

Weather.CONDITION_FOGGY

Not provided

Not provided

Constant

Weather.CONDITION_HAZY

Not provided

Not provided

Constant

Weather.CONDITION_ICY

Not provided

Not provided

Constant

Weather.CONDITION_RAINY

Not provided

Not provided

Constant

Weather.CONDITION_SNOWY

Not provided

Not provided

Constant

Weather.CONDITION_STORMY

Not provided

Not provided

Constant

Weather.CONDITION_UNKNOWN

Not provided

Not provided

Constant

Weather.CONDITION_WINDY

Not provided

Not provided

Constant

Weather.FAHRENHEIT

Not provided

Not provided

Deprecated APIs in the Awareness Class

The following Google APIs in the Awareness class have been deprecated.

Type

Deprecated API

Replacement API

Attribute

Awareness.FenceApi

Awareness.getFenceClient(Activity activity)

Attribute

Awareness.SnapshotApi

Awareness.getSnapshotClient(Activity activity)

You need to update the deprecated Google APIs in the Awareness class to the replacement APIs getFenceClient(Activity activity) and getSnapshotClient(Activity activity) provided by Google, and then use the tool for automatic conversion. If the APIs are not updated, refer to the following instructions for manual conversion.

The following is the mapping between the deprecated Google APIs in the Awareness class and the replacement APIs of HMS.

Google API

To HMS API

Add HMS API

Awareness.FenceApi

Awareness.getBarrierClient(Activity activity)

Awareness.getFenceClient(Activity activity)

Awareness.SnapshotApi

Awareness.getCaptureClient(Activity activity)

Awareness.getSnapshotClient(Activity activity)

To HMS API method for FenceApi:

Awareness.getBarrierClient(Activity);

Add HMS API method for FenceApi:

Awareness.getFenceClient(Activity);

To HMS API method for SnapshotApi:

Awareness.getCaptureClient(Activity);

Add HMS API method for SnapshotApi:

Awareness.getSnapshotClient(Activity);

Deprecated APIs in the FenceApi Class

The following Google APIs in the FenceApi class have been deprecated.

Type

Deprecated API

Replacement API

Method

FenceApi.queryFences(GoogleApiClient, FenceQueryRequest)

FenceClient.queryFences(FenceQueryRequest)

Method

FenceApi.updateFences(GoogleApiClient, FenceUpdateRequest)

FenceClient.updateFences(FenceQueryRequest)

You need to update the deprecated Google APIs in the FenceApi class to the queryFences(FenceQueryRequest) and updateFences(FenceQueryRequest) APIs, and then use the tool for automatic conversion. If the APIs are not updated, refer to the following instructions for manual conversion.

Google API

To HMS API

Add HMS API

FenceApi.queryFences(GoogleApiClient, FenceQueryRequest)

BarrierClient.queryBarriers(BarrierQueryRequest)

FenceClient.queryFences(FenceQueryRequest)

FenceApi.updateFences(GoogleApiClient, FenceUpdateRequest)

BarrierClient.updateBarriers(BarrierUpdateRequest)

FenceClient.updateFences(FenceQueryRequest)

Google API implementation method of the queryFences(GoogleApiClient, FenceQueryReqest) API:

GoogleApiClient mGoogleApiClient;
mGoogleApiClient = new GoogleApiClient.Builder(this).addApi(Awareness.API).build();
mGoogleApiClient.connect();
// Build a request body.
FenceQueryRequest request = FenceQueryRequest.all();
// Initiate a request.
Awareness.FenceApi.queryFences(mGoogleApiClient, request).setResultCallback(new ResultCallback<FenceQueryResult>() {
    @Override
    public void onResult(FenceQueryResult fenceQueryResult) {
    // Process the result.
    ...
    }
});

To HMS API method for queryFences(GoogleApiClient, FenceQueryRequest):

// Build a request body.
BarrierQueryRequest query = BarrierQueryRequest.all();
// Initiate a request.
Awareness.getBarrierClient(this).queryBarriers(query).addOnSuccessListener(new OnSuccessListener<BarrierQueryResponse>() {
    @Override   
    public void onSuccess(BarrierQueryResponse barrierQueryResponse) {        
    // Process the result.
    ...
     }
});

Add HMS API method for queryFences(GoogleApiClient, FenceQueryRequest):

// Build a request body.
FenceQueryRequest query = FenceQueryRequest.all();
// Initiate a request.
Awareness.getFenceClient(this).queryFences(query).addOnSuccessListener(new OnSuccessListener<FenceQueryResponse>() {
    @Override    
    public void onSuccess(FenceQueryResponse param0) {     
        // Process the result.        
...
    }
});

Google API implementation method of the updateFences(GoogleApiClient, FenceUpdateRequest) API:

GoogleApiClient googleApiClient = new GoogleApiClient.Builder(this).addApi(Awareness.API).build();
googleApiClient.connect();
// Create a barrier.
AwarenessFence headphoneFence = HeadphoneFence.pluggingIn();
Intent intent = new Intent();
PendingIntent pendingIntent = PendingIntent.getBroadcast(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
// Update the barrier.
Awareness.FenceApi.updateFences(googleApiClient, new FenceUpdateRequest.Builder()
             .addFence("HEAD_PHONE_CONNECTING", headphoneFence,pendingIntent)
             .build());

To HMS API method for updateFences(GoogleApiClient, FenceUpdateRequest):

// Create a barrier.
AwarenessBarrier headsetBarrier = HeadsetBarrier.connecting();
Intent intent = new Intent();
PendingIntent pendingIntent=PendingIntent.getBroadcast(this, 0, intent,PendingIntent.FLAG_UPDATE_CURRENT);
// Update the barrier.
Awareness.getBarrierClient(this).updateBarriers(new BarrierUpdateRequest.Builder()
                     .addBarrier("HEAD_SET_CONNECTING", headsetBarrier, pendingIntent)
                     .build());

Add HMS API method for updateFences(GoogleApiClient, FenceQueryRequest):

// Create a barrier.
AwarenessFence headphoneFence = HeadphoneFence.pluggingIn();
Intent intent = new Intent();
PendingIntent pendingIntent=PendingIntent.getBroadcast(this, 0, intent, PendingIntent.FLAG_UPDATE_CURRENT);
// Update the barrier.
Awareness.getFenceClient(this).updateFences(new FenceUpdateRequest.Builder()
                   .addFence("HEAD_PHONE_CONNECTING",headphoneFence,pendingIntent)
                   .build());

Deprecated APIs in the SnapshotApi Class

The following Google APIs in the SnapshotApi class have been deprecated.

Type

Deprecated API

Replacement API

Method

SnapshotApi.getDetectedActivity(GoogleApiClient)

SnapshotClient.getDetectedActivity()

Method

SnapshotApi.getHeadphoneState(GoogleApiClient)

SnapshotClient.getHeadphoneState()

Method

SnapshotApi.getLocation(GoogleApiClient)

SnapshotClient.getLocation()

Method

SnapshotApi.getTimeIntervals(GoogleApiClient)

SnapshotClient.getTimeIntervals()

Method

SnapshotApi.getBeaconState(GoogleApiClient, Collection<BeaconState.TypeFilter>)

SnapshotClient.getBeaconState (Collection<BeaconState. TypeFilter>)(

Method

SnapshotApi.getBeaconState(GoogleApiClient, TypeFilter...)

SnapshotClient.getBeaconState(BeaconState.TypeFilter...)

You need to update the deprecated APIs in the SnapshotApi class to the new APIs getBeaconState(BeaconState.Filter...), getDetectedActivity(), getHeadphoneState(), getLocation(), and getTimeIntervals() provided by Google, and then use the tool for automatic conversion. If the APIs are not updated, refer to the following instructions for manual conversion.

Google API

To HMS API

Add HMS API

SnapshotApi.getDetectedActivity(GoogleApiClient)

CaptureClient.getBehavior()

SnapshotClient.getDetectedActivity()

SnapshotApi.getHeadphoneState(GoogleApiClient)

CaptureClient.getHeadsetStatus()

SnapshotClient.getHeadphoneState()

SnapshotApi.getLocation(GoogleApiClient)

CaptureClient.getLocation()

SnapshotClient.getLocation()

SnapshotApi.getTimeIntervals(GoogleApiClient)

CaptureClient.getTimeCategories()

SnapshotClient.getTimeIntervals()

SnapshotApi.getBeaconState(GoogleApiClient, Collection<BeaconState.TypeFilter>)

CaptureClient.getBeaconStatus(Collection<BeaconStatus.Filter>)

SnapshotClient.getBeaconState (Collection<BeaconState. TypeFilter>)

SnapshotApi.getBeaconState(GoogleApiClient, TypeFilter...)

CaptureClient.getBeaconStatus(BeaconStatus.Filter…)

SnapshotClient.getBeaconState(BeaconState.TypeFilter...)

Google API implementation method of the getDetectedActivity(GoogleApiClient) API:

GoogleApiClient mGoogleApiClient;
mGoogleApiClient = new GoogleApiClient.Builder(this).addApi(Awareness.API).build();
mGoogleApiClient.connect();
// Initiate a request.
Awareness.SnapshotApi.getDetectedActivity(mGoogleApiClient).setResultCallback(new ResultCallback<DetectedActivityResult>() {
    @Override
    public void onResult(@NonNull DetectedActivityResult detectedActivityResult) {
         // Obtain the result.         
        if (detectedActivityResult.getStatus().isSuccess()) {
               ...
         }
     }
});

To HMS API method for getDetectedActivity(GoogleApiClient):

Awareness.getCaptureClient(this).getBehavior().addOnSuccessListener(new OnSuccessListener<BehaviorResponse>() {
    @Override
    public void onSuccess(BehaviorResponse behaviorResponse) {
                ...
     }
});

Add HMS API method for getDetectedActivity(GoogleApiClient):

Awareness.getSnapshotClient(this).getDetectedActivity().addOnSuccessListener(new OnSuccessListener<DetectedActivityResponse>() {
    @Override
    public void onSuccess(DetectedActivityResponse param0) {
               ...
    }
});

Google API implementation method of the getHeadphoneState(GoogleApiClient) API:

GoogleApiClient mGoogleApiClient;
mGoogleApiClient = new GoogleApiClient.Builder(this).addApi(Awareness.API).build();
mGoogleApiClient.connect();
// Initiate a request.
Awareness.SnapshotApi.getHeadphoneState(mGoogleApiClient).setResultCallback(new ResultCallback<HeadphoneStateResult>() {
    @Override
    public void onResult(@NonNull HeadphoneStateResult headphoneStateResult) {
      // Obtain the result.        
        if (headphoneStateResult.getStatus().isSuccess()) {
             ...
        }
    }
});

To HMS API method for getHeadphoneState(GoogleApiClient):

Awareness.getCaptureClient(this).getHeadsetStatus().addOnSuccessListener(new OnSuccessListener<HeadsetStatusResponse>() {
    @Override
    public void onSuccess(HeadsetStatusResponse headsetStatusResponse) {
                ...
    }
});

Add HMS API method for getHeadphoneState(GoogleApiClient):

Awareness.getSnapshotClient(this).getHeadphoneState().addOnSuccessListener(new OnSuccessListener<HeadphoneStateResponse>() {
    @Override
    public void onSuccess(HeadphoneStateResponse param0) {
                   ...
    }
});

Google API implementation method of the getLocation(GoogleApiClient) API:

GoogleApiClient mGoogleApiClient;
mGoogleApiClient = new GoogleApiClient.Builder(this).addApi(Awareness.API).build();
mGoogleApiClient.connect();
// Initiate a request.
Awareness.SnapshotApi.getLocation(mGoogleApiClient).setResultCallback(new ResultCallback<LocationResult>() {
    @Override
    public void onResult(@NonNull LocationResult locationResult) {
    // Obtain the result.
        if (locationResult.getStatus().isSuccess()) {
              ...
          }
    }
});

To HMS API method for getLocation(GoogleApiClient):

// Check the location permission.
if(checkSelfPermission(Manifest.permission.ACCESS_FINE_LOCATION)!=PackageManager.PERMISSION_GRANTED) {
    return;
}
// Initiate a request.
Awareness.getCaptureClient(this).getLocation().addOnSuccessListener(new OnSuccessListener<LocationResponse>() {
    @Override
    public void onSuccess(LocationResponse locationResponse) {
                            //Process the result.
                            ...
    }
});

Add HMS API method for getLocation(GoogleApiClient):

// Check the location permission.
if(checkSelfPermission(Manifest.permission.ACCESS_FINE_LOCATION) !=PackageManager.PERMISSION_GRANTED) {
    return;
     }
// Initiate a request.
Awareness.getSnapshotClient(this).getLocation().addOnSuccessListener(new OnSuccessListener<LocationResponse>() {
    @Override
    public void onSuccess(LocationResponse param0) {
        // Process the result.
            ...
     }
});
Google API implementation method of getBeaconState(GoogleApiClient, TypeFilter...): Same method for getBeaconState(GoogleApiClient, Collection<BeaconState.TypeFilter>)
GoogleApiClient mGoogleApiClient;
mGoogleApiClient = new GoogleApiClient.Builder(this).addApi(Awareness.API).build();
mGoogleApiClient.connect();
// Initiate a request.
Awareness.SnapshotApi.getBeaconState(mGoogleApiClient, BEACON_TYPE_FILTERS).setResultCallback(new ResultCallback<BeaconStateResult>() {
    @Override           
    public void onResult(BeaconStateResult beaconStateResult) {
    // Process the result.
        if (beaconStateResult.getStatus().isSuccess()) { 
             ...
          }
     }            
 });

To HMS API method for getBeaconState(TypeFilter...): Same method for getBeaconState(GoogleApiClient, Collection<BeaconState.TypeFilter>)

// Initiate a request.
Awareness.getCaptureClient(this).getBeaconStatus(BEACON_TYPE_FILTERS).addOnSuccessListener(new OnSuccessListener<BeaconStatusResponse>(){
    @Override            
    public void onSuccess(BeaconStatusResponse beaconStatusResponse) {
        // Process the result.
        ...
     }     
});

Add HMS API method for getBeaconState(TypeFilter...): Same method for getBeaconState(GoogleApiClient, Collection<BeaconState.TypeFilter>)

// Initiate a request.
Awareness.getSnapshotClient(this).getBeaconState(BEACON_TYPE_FILTERS).addOnSuccessListener(new OnSuccessListener<BeaconStateResponse>(){
    @Override            
    public void onSuccess(BeaconStateResponse param0) {
        // Process the result.
         ...
     }     
});

Google API implementation method of getTimeIntervals(GoogleApiClient):

GoogleApiClient mGoogleApiClient;
mGoogleApiClient = new GoogleApiClient.Builder(this).addApi(Awareness.API).build();
mGoogleApiClient.connect();
// Initiate a request.
Awareness.SnapshotApi.getTimeIntervals(mGoogleApiClient).setResultCallback(new ResultCallback<TimeIntervalsResult>() {
    @Override
    public void onResult(@NonNull TimeIntervalsResult timeIntervalsResult) {
    // Process the result.
        if (timeIntervalsResult.getStatus().isSuccess()) {
               ...
          }
     }
});
To HMS API method for getTimeIntervals(GoogleApiClient):
// Initiate a request.
Awareness.getCaptureClient(this).getTimeCategories().addOnSuccessListener(new OnSuccessListener<TimeCategoriesResponse>() {
    @Override
    public void onSuccess(TimeCategoriesResponse timeCategoriesResponse) {
                            // Process the result.
                            ...
    }
});

Add HMS API method for getTimeIntervals(GoogleApiClient):

// Initiate a request.
Awareness.getSnapshotClient(this).getTimeIntervals().addOnSuccessListener(new OnSuccessListener<TimeIntervalsResponse>() {
    @Override
    public void onSuccess(TimeIntervalsResponse param0) {
             // Process the result.
             ...
    }
});

Deprecated Status Codes and Their Replacements

The status codes in the AwarenessStatusCodes class of Google APIs have been deprecated. HMS provides new status codes.

Type

Google Status Code

Constant

int ACL_ACCESS_DENIED = 7503

Constant

int API_NOT_AVAILABLE = 7512

Constant

int BAD_ACCOUNT = 7504

Constant

int BLUETOOTH_OFF = 7506

Constant

int FENCE_NOT_AVAILABLE = 7514

Constant

int INCONSISTENT_ACCOUNT = 7510

Constant

int INCONSISTENT_MODULE_ID = 7511

Constant

int INCONSISTENT_UID = 7513

Constant

int INTERNAL_API_CLIENT_CONNECTION_FAILED = 7507

Constant

int MAX_LIMIT_OF_FENCE_REGISTRATIONS_EXCEEDED = 7515

Type

HMS Status Code

Constant

int AWARENESS_SUCCESS_CODE = 0

Constant

int AWARENESS_UNKNOWN_ERROR_CODE = 10000

Constant

int AWARENESS_BINDER_ERROR_CODE = 10001

Constant

int AWARENESS_REGISTER_FAILED_CODE = 10002

Constant

int AWARENESS_TIMEOUT_CODE = 10003

Constant

int AWARENESS_COUNT_LIMIT_CODE = 10004

Constant

int AWARENESS_FREQUENCY_LIMIT_CODE = 10005

Constant

int AWARENESS_BARRIER_PARAMETER_ERROR_CODE = 10006

Constant

int AWARENESS_REQUEST_ERROR_CODE = 10007

Constant

int AWARENESS_AGC_FILE_ERROR = 10008

Constant

int AWARENESS_RESULT_INVALID_ERROR = 10009

Constant

int AWARENESS_REMOTE_EXCEPTION_ERROR = 10010

Constant

int AWARENESS_WAIT_CALLBACK_CODE = 10011

Constant

int AWARENESS_SDK_VERSION_ERROR = 10100

Constant

int AWARENESS_LOCATION_NOCACHE_CODE = 10200

Constant

int AWARENESS_LOCATION_NOT_AVAILABLE_CODE = 10201

Constant

int AWARENESS_LOCATION_PERMISSION_CODE = 10101

Constant

int AWARENESS_LOCATION_CORE_PERMISSION_CODE = 10102

Constant

int AWARENESS_BEHAVIOR_PERMISSION_CODE = 10103

Constant

int AWARENESS_BEACON_NOT_AVAILABLE_CODE = 10300