Skip to content

Commit

Permalink
Check for activityRecognitionPermitted in ActivityRecognitionLocation…
Browse files Browse the repository at this point in the history
…Provider (#198)

* Check for activityRecognitionPermitted in ActivityRecognitionLocationProvider

* Fix typo
  • Loading branch information
pmlodawski authored Aug 2, 2024
1 parent 8c09a68 commit 2a4c773
Showing 1 changed file with 8 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,13 @@
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.content.pm.PackageManager;
import android.location.Location;
import android.Manifest;
import android.os.Build;
import android.os.Bundle;
import android.os.PowerManager;
import androidx.core.app.ActivityCompat;
import android.util.Log;

import com.google.android.gms.common.ConnectionResult;
Expand Down Expand Up @@ -147,13 +150,17 @@ private void disconnectFromPlayAPI() {
}
}

private boolean activityRecognitionPermitted() {
return Build.VERSION.SDK_INT < Build.VERSION_CODES.Q || ActivityCompat.checkSelfPermission(mContext, Manifest.permission.ACTIVITY_RECOGNITION) == PackageManager.PERMISSION_GRANTED;
}

private void attachRecorder() {
if (googleApiClient == null) {
connectToPlayAPI();
} else if (googleApiClient.isConnected()) {
if (isWatchingActivity) { return; }
startTracking();
if (mConfig.getStopOnStillActivity()) {
if (mConfig.getStopOnStillActivity() && activityRecognitionPermitted()) {
ActivityRecognition.ActivityRecognitionApi.requestActivityUpdates(
googleApiClient,
mConfig.getActivitiesInterval(),
Expand Down

0 comments on commit 2a4c773

Please sign in to comment.