Skip to content

Commit

Permalink
Removed Location Permissions for >= Android 12
Browse files Browse the repository at this point in the history
  • Loading branch information
mspider65 committed Apr 8, 2023
1 parent 63023b0 commit 699dd46
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 8 deletions.
4 changes: 3 additions & 1 deletion app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" android:maxSdkVersion="30" />

<!-- New BLE Permissions (>= Android 12) -->
<uses-permission android:name="android.permission.BLUETOOTH_SCAN" />
<uses-permission android:name="android.permission.BLUETOOTH_SCAN"
android:usesPermissionFlags="neverForLocation"
tools:targetApi="s" />
<uses-permission android:name="android.permission.BLUETOOTH_CONNECT" />

<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -424,8 +424,7 @@ public void onRequestPermissionsResult(int requestCode, @NonNull String[] permis
if (requestCode == APP_PERMISSION_REQUEST) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
if ((ContextCompat.checkSelfPermission(this, Manifest.permission.BLUETOOTH_SCAN) == PackageManager.PERMISSION_GRANTED)
&& (ContextCompat.checkSelfPermission(this, Manifest.permission.BLUETOOTH_CONNECT) == PackageManager.PERMISSION_GRANTED)
&& (ContextCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED))
&& (ContextCompat.checkSelfPermission(this, Manifest.permission.BLUETOOTH_CONNECT) == PackageManager.PERMISSION_GRANTED))
return;
} else {
if ((ContextCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) == PackageManager.PERMISSION_GRANTED)
Expand Down Expand Up @@ -595,15 +594,13 @@ private void checkBT() {
@RequiresApi(api = Build.VERSION_CODES.S)
private static final String[] ANDROID_12_BLE_PERMISSIONS = new String[]{
Manifest.permission.BLUETOOTH_SCAN,
Manifest.permission.BLUETOOTH_CONNECT,
Manifest.permission.ACCESS_FINE_LOCATION
Manifest.permission.BLUETOOTH_CONNECT
};

private void checkPermissions() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
if ((ContextCompat.checkSelfPermission(this, Manifest.permission.BLUETOOTH_SCAN) != PackageManager.PERMISSION_GRANTED)
|| (ContextCompat.checkSelfPermission(this, Manifest.permission.BLUETOOTH_CONNECT) != PackageManager.PERMISSION_GRANTED)
|| (ContextCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED))
|| (ContextCompat.checkSelfPermission(this, Manifest.permission.BLUETOOTH_CONNECT) != PackageManager.PERMISSION_GRANTED))
ActivityCompat.requestPermissions(this, ANDROID_12_BLE_PERMISSIONS, APP_PERMISSION_REQUEST);
} else {
if ((ContextCompat.checkSelfPermission(this, Manifest.permission.ACCESS_FINE_LOCATION) != PackageManager.PERMISSION_GRANTED)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ public void stopScanning() {
@SuppressLint("MissingPermission")
@Override
public void onScanResult(int callbackType, ScanResult result) {
Log.d(TAG, "onScanResult " + result.getDevice().getName());
Log.d(TAG, "onScanResult " + result.getDevice().getName() + " - " + result.getDevice().getAddress());
String devName = result.getDevice().getName();
if (devName != null && !devName.isEmpty()) {
devName = devName.concat(" - ").concat(result.getDevice().getAddress());
Expand Down

0 comments on commit 699dd46

Please sign in to comment.