Skip to content

Commit

Permalink
Merge pull request #42 from vanniktech/isLocationPermissionGranted
Browse files Browse the repository at this point in the history
Add helper method isLocationPermissionGranted.
  • Loading branch information
IvBaranov authored Oct 22, 2018
2 parents cf56e2a + c168086 commit 7f1e469
Showing 1 changed file with 19 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.Build;
import android.content.pm.PackageManager;
import android.text.TextUtils;
import com.github.ivbaranov.rxbluetooth.events.AclEvent;
import com.github.ivbaranov.rxbluetooth.events.BondStateEvent;
Expand All @@ -43,6 +43,9 @@
import java.util.UUID;
import java.util.concurrent.Callable;

import static android.Manifest.permission.ACCESS_COARSE_LOCATION;
import static android.os.Build.VERSION.SDK_INT;

/**
* Enables clients to listen to bluetooth events using RxJava Observables.
*/
Expand Down Expand Up @@ -77,6 +80,20 @@ public boolean isBluetoothEnabled() {
return bluetoothAdapter.isEnabled();
}

/**
* Return true if Location permission is granted.
*
* @return true if the local permission is granted. Pre 23 it will always return true. Post 22
* it will ask the Context whether the permission has been granted or not.
*/
public boolean isLocationPermissionGranted() {
if (SDK_INT >= 23) {
return context.checkSelfPermission(ACCESS_COARSE_LOCATION) == PackageManager.PERMISSION_GRANTED;
}

return true;
}

/**
* This will issue a request to enable Bluetooth through the system settings (without stopping
* your application) via ACTION_REQUEST_ENABLE action Intent.
Expand Down Expand Up @@ -513,7 +530,7 @@ public Observable<BluetoothSocket> observeConnectDevice(final BluetoothDevice bl
try {
bluetoothSocket.close();
} catch (IOException suppressed) {
if (Build.VERSION.SDK_INT >= 19) {
if (SDK_INT >= 19) {
e.addSuppressed(suppressed);
}
}
Expand Down

0 comments on commit 7f1e469

Please sign in to comment.