Skip to content

Commit

Permalink
Merge pull request #43 from vanniktech/isLocationServiceEnabled
Browse files Browse the repository at this point in the history
Add helper method isLocationServiceEnabled.
  • Loading branch information
IvBaranov authored Oct 22, 2018
2 parents 7f1e469 + 529dbaa commit dececd0
Showing 1 changed file with 13 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import android.content.Intent;
import android.content.IntentFilter;
import android.content.pm.PackageManager;
import android.location.LocationManager;
import android.text.TextUtils;
import com.github.ivbaranov.rxbluetooth.events.AclEvent;
import com.github.ivbaranov.rxbluetooth.events.BondStateEvent;
Expand All @@ -44,6 +45,8 @@
import java.util.concurrent.Callable;

import static android.Manifest.permission.ACCESS_COARSE_LOCATION;
import static android.location.LocationManager.GPS_PROVIDER;
import static android.location.LocationManager.NETWORK_PROVIDER;
import static android.os.Build.VERSION.SDK_INT;

/**
Expand Down Expand Up @@ -94,6 +97,16 @@ public boolean isLocationPermissionGranted() {
return true;
}

/**
* Return true if a location service is enabled.
*
* @return true if either the GPS or Network provider is enabled
*/
public boolean isLocationServiceEnabled() {
LocationManager locationManager = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE);
return locationManager.isProviderEnabled(GPS_PROVIDER) || locationManager.isProviderEnabled(NETWORK_PROVIDER);
}

/**
* This will issue a request to enable Bluetooth through the system settings (without stopping
* your application) via ACTION_REQUEST_ENABLE action Intent.
Expand Down

0 comments on commit dececd0

Please sign in to comment.