Skip to content

Commit

Permalink
fix crash in location helper
Browse files Browse the repository at this point in the history
  • Loading branch information
jvde-github committed Nov 11, 2023
1 parent 17c9de7 commit 410a029
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ android {
applicationId "com.jvdegithub.aiscatcher"
minSdk 23
targetSdk 33
versionCode 86
versionName '0.86'
versionCode 87
versionName '0.87'

testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
externalNativeBuild {
Expand Down
14 changes: 12 additions & 2 deletions app/src/main/java/com/jvdegithub/aiscatcher/LocationHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import android.location.LocationManager;
import android.os.Bundle;
import android.util.Log;
import android.widget.Toast;

import androidx.annotation.NonNull;
import androidx.core.app.ActivityCompat;
Expand All @@ -33,11 +34,20 @@ public void requestLocationUpdates() {
new String[]{Manifest.permission.ACCESS_FINE_LOCATION, Manifest.permission.ACCESS_COARSE_LOCATION},
PERMISSION_REQUEST_CODE);
} else {
locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 5 * 60 * 1000, 0, this);
isUpdatingLocation = true;
if (locationManager.isProviderEnabled(LocationManager.GPS_PROVIDER)) {
locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 5 * 60 * 1000, 0, this);
isUpdatingLocation = true;
} else if (locationManager.isProviderEnabled(LocationManager.NETWORK_PROVIDER)) {
locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 5 * 60 * 1000, 0, this);
isUpdatingLocation = true;

Toast.makeText(context, "GPS not available. Using network for location updates.", Toast.LENGTH_LONG).show();
} else {
}
}
}


@Override
public void onLocationChanged(Location location) {
Log.d("Location Update", String.format("New Location Received: (Latitude: %s, Longitude: %s)",
Expand Down

0 comments on commit 410a029

Please sign in to comment.