Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add helper method isLocationPermissionGranted. #42

Merged
merged 1 commit into from
Oct 22, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -519,7 +536,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