Skip to content

Commit 120cc5e

Browse files
authored
Merge pull request #114 from NordicSemiconductor/android12
Migration to Android 12
2 parents e691c2b + 16994e5 commit 120cc5e

File tree

7 files changed

+184
-108
lines changed

7 files changed

+184
-108
lines changed

moustache/README.mo

Lines changed: 25 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ This is much less battery friendly than when the original method is used, but wo
2222
a lot of development time if such feature should be implemented anyway. Please read below
2323
for more details.
2424

25+
Note, that for unfiltered scans, scanning is stopped on screen off to save power. Scanning is
26+
resumed when screen is turned on again. To avoid this, use scanning with desired ScanFilter.
27+
2528
## Usage
2629

2730
The compat library may be found on Maven Central repository. Add it to your project by adding the
@@ -31,6 +34,8 @@ following dependency:
3134
implementation 'no.nordicsemi.android.support.v18:scanner:{{VERSION}}'
3235
```
3336

37+
Project not targeting API 31 (Android 12) or newer should use version 1.5.1.
38+
3439
Projects not migrated to Android Jetpack should use version 1.3.1, which is feature-equal to 1.4.0.
3540

3641
As JCenter has shut down, starting from version 1.4.4 the library is available only on Maven Central.
@@ -57,10 +62,21 @@ already enabled desugaring. But if this causes problems for you, please use vers
5762

5863
Following [this](https://developer.android.com/reference/android/bluetooth/le/BluetoothLeScanner#startScan(android.bluetooth.le.ScanCallback)) link:
5964

60-
> An app must have [ACCESS_COARSE_LOCATION](https://developer.android.com/reference/android/Manifest.permission#ACCESS_COARSE_LOCATION) permission in order to get results. An App targeting Android Q or later must have [ACCESS_FINE_LOCATION](https://developer.android.com/reference/android/Manifest.permission#ACCESS_FINE_LOCATION) permission in order to get results.
61-
For apps targeting [Build.VERSION_CODES#R](https://developer.android.com/reference/android/os/Build.VERSION_CODES#R) or lower, this requires the [Manifest.permission#BLUETOOTH_ADMIN](https://developer.android.com/reference/android/Manifest.permission#BLUETOOTH_ADMIN) permission which can be gained with a simple `<uses-permission>` manifest tag.
62-
For apps targeting [Build.VERSION_CODES#S](https://developer.android.com/reference/android/os/Build.VERSION_CODES#S) or or higher, this requires the [Manifest.permission#BLUETOOTH_SCAN](https://developer.android.com/reference/android/Manifest.permission#BLUETOOTH_SCAN) permission which can be gained with [Activity.requestPermissions(String[], int)](https://developer.android.com/reference/android/app/Activity#requestPermissions(java.lang.String[],%20int)).
63-
In addition, this requires either the [Manifest.permission#ACCESS_FINE_LOCATION](https://developer.android.com/reference/android/Manifest.permission#ACCESS_FINE_LOCATION) permission or a strong assertion that you will never derive the physical location of the device. You can make this assertion by declaring `usesPermissionFlags="neverForLocation"` on the relevant `<uses-permission>` manifest tag, but it may restrict the types of Bluetooth devices you can interact with.
65+
> An app must have [ACCESS_COARSE_LOCATION](https://developer.android.com/reference/android/Manifest.permission#ACCESS_COARSE_LOCATION)
66+
permission in order to get results. An App targeting Android Q or later must have
67+
[ACCESS_FINE_LOCATION](https://developer.android.com/reference/android/Manifest.permission#ACCESS_FINE_LOCATION)
68+
permission in order to get results.
69+
For apps targeting [Build.VERSION_CODES#R](https://developer.android.com/reference/android/os/Build.VERSION_CODES#R)
70+
or lower, this requires the [Manifest.permission#BLUETOOTH_ADMIN](https://developer.android.com/reference/android/Manifest.permission#BLUETOOTH_ADMIN)
71+
permission which can be gained with a simple `<uses-permission>` manifest tag.
72+
For apps targeting [Build.VERSION_CODES#S](https://developer.android.com/reference/android/os/Build.VERSION_CODES#S)
73+
or or higher, this requires the [Manifest.permission#BLUETOOTH_SCAN](https://developer.android.com/reference/android/Manifest.permission#BLUETOOTH_SCAN)
74+
permission which can be gained with
75+
[Activity.requestPermissions(String[], int)](https://developer.android.com/reference/android/app/Activity#requestPermissions(java.lang.String[],%20int)).
76+
In addition, this requires either the [Manifest.permission#ACCESS_FINE_LOCATION](https://developer.android.com/reference/android/Manifest.permission#ACCESS_FINE_LOCATION)
77+
permission or a strong assertion that you will never derive the physical location of the device.
78+
You can make this assertion by declaring `usesPermissionFlags="neverForLocation"` on the relevant
79+
`<uses-permission>` manifest tag, but it may restrict the types of Bluetooth devices you can interact with.
6480

6581
## API
6682

@@ -178,7 +194,7 @@ the application. No changes are required to make it work.
178194
To use this feature:
179195

180196
```java
181-
Intent intent = new Intent(context, MyReceiver.class); // explicite intent
197+
Intent intent = new Intent(context, MyReceiver.class); // explicit intent
182198
intent.setAction("com.example.ACTION_FOUND");
183199
intent.putExtra("some.extra", value); // optional
184200
PendingIntent pendingIntent = PendingIntent.getBroadcast(context, requestCode, intent, PendingIntent.FLAG_UPDATE_CURRENT);
@@ -193,7 +209,7 @@ To use this feature:
193209
scanner.startScan(filters, settings, context, pendingIntent, requestCode);
194210
```
195211

196-
Add your `MyRecever` to *AndroidManifest*, as the application context might have been released
212+
Add your `MyReceiver` to *AndroidManifest*, as the application context might have been released
197213
and all broadcast receivers registered to it together with it.
198214

199215
To stop scanning call:
@@ -227,6 +243,9 @@ Background scanning on Android 4.3 and 4.4.x will use a lot of power, as all tho
227243
will have to be emulated. It is recommended to scan in background only on Lollipop or newer, or
228244
even Oreo or newer devices and giving the user an option to disable this feature.
229245

246+
Note, that for unfiltered scans, scanning is stopped on screen off to save power. Scanning is
247+
resumed when screen is turned on again. To avoid this, use scanning with desired ScanFilter.
248+
230249
## License
231250

232251
The Scanner Compat library is available under BSD 3-Clause license. See the LICENSE file for more info.

scanner/build.gradle

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
apply plugin: 'com.android.library'
22

33
android {
4-
compileSdkVersion 30
4+
compileSdkVersion 31
55

66
defaultConfig {
77
minSdkVersion 18
8-
targetSdkVersion 30
8+
targetSdkVersion 31
99
versionCode 21
1010

1111
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
@@ -19,10 +19,6 @@ android {
1919
testCoverageEnabled true
2020
}
2121
}
22-
compileOptions {
23-
sourceCompatibility JavaVersion.VERSION_1_8
24-
targetCompatibility JavaVersion.VERSION_1_8
25-
}
2622
}
2723

2824
dependencies {

scanner/src/main/AndroidManifest.xml

Lines changed: 21 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,16 +3,31 @@
33
xmlns:tools="http://schemas.android.com/tools">
44

55
<!--
6-
Bluetooth permissions require to check Bluetooth Adapter state
7-
and starting LE scan.
6+
Bluetooth permissions require to check Bluetooth Adapter state
7+
and starting LE scan before Android S (API 31).
88
-->
9-
<uses-permission android:name="android.permission.BLUETOOTH"/>
10-
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN"/>
9+
<uses-permission
10+
android:name="android.permission.BLUETOOTH"
11+
android:maxSdkVersion="30"/>
12+
<uses-permission
13+
android:name="android.permission.BLUETOOTH_ADMIN"
14+
android:maxSdkVersion="30"/>
1115
<!--
12-
Location permission is required on Android 6+.
13-
Since Android 10 the FINE LOCATION will be required.
16+
Bluetooth Scan permission is required from Android S onwards.
17+
18+
Note: This permission may be used with "usesPermissionFlag". If you don't need location,
19+
declare this permission with this flag set to "neverForLocation".
1420
-->
21+
<uses-permission
22+
android:name="android.permission.BLUETOOTH_SCAN" />
23+
24+
<!--
25+
Location permission has been removed from here, as it may not be required for
26+
Android 12 onwards. It is required on Android 6-11 when scanning for Bluetooth LE devices.
27+
28+
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
1529
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
30+
-->
1631

1732
<application>
1833
<!--

0 commit comments

Comments
 (0)