Skip to content

Commit aaee405

Browse files
committed
Merge branch 'espresso/master' into skugga
# Conflicts: # android/build.gradle
2 parents 6916ae7 + 9758034 commit aaee405

15 files changed

+605
-601
lines changed

.metadata

+10-10
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
# This file tracks properties of this Flutter project.
2-
# Used by Flutter tool to assess capabilities and perform upgrades etc.
3-
#
4-
# This file should be version controlled and should not be manually edited.
5-
6-
version:
7-
revision: f53b32eb2317ba09137969999d130c24a6314997
8-
channel: master
9-
10-
project_type: plugin
1+
# This file tracks properties of this Flutter project.
2+
# Used by Flutter tool to assess capabilities and perform upgrades etc.
3+
#
4+
# This file should be version controlled and should not be manually edited.
5+
6+
version:
7+
revision: f53b32eb2317ba09137969999d130c24a6314997
8+
channel: master
9+
10+
project_type: plugin

README.md

+42-40
Original file line numberDiff line numberDiff line change
@@ -27,45 +27,6 @@ Using the FlutterBlue instance, you can scan for and connect to nearby devices (
2727
Once connected to a device, the BluetoothDevice object can discover services ([BluetoothService](lib/src/bluetooth_service.dart)), characteristics ([BluetoothCharacteristic](lib/src/bluetooth_characteristic.dart)), and descriptors ([BluetoothDescriptor](lib/src/bluetooth_descriptor.dart)).
2828
The BluetoothDevice object is then used to directly interact with characteristics and descriptors.
2929

30-
## Setup
31-
### Change the minSdkVersion for Android
32-
33-
Flutter_blue is compatible only from version 19 of Android SDK so you should change this in **android/app/build.gradle**:
34-
```dart
35-
Android {
36-
defaultConfig {
37-
minSdkVersion: 19
38-
```
39-
### Add permissions for Bluetooth
40-
We need to add the permission to use Bluetooth and access location:
41-
42-
#### **Android**
43-
In the **android/app/src/main/AndroidManifest.xml** let’s add:
44-
45-
```dart
46-
<uses-permission android:name="android.permission.BLUETOOTH" />
47-
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
48-
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
49-
<application
50-
```
51-
#### **IOS**
52-
In the **ios/Runner/Info.plist** let’s add:
53-
54-
```dart
55-
<dict>
56-
<key>NSBluetoothAlwaysUsageDescription</key>
57-
<string>Need BLE permission</string>
58-
<key>NSBluetoothPeripheralUsageDescription</key>
59-
<string>Need BLE permission</string>
60-
<key>NSLocationAlwaysAndWhenInUseUsageDescription</key>
61-
<string>Need Location permission</string>
62-
<key>NSLocationAlwaysUsageDescription</key>
63-
<string>Need Location permission</string>
64-
<key>NSLocationWhenInUseUsageDescription</key>
65-
<string>Need Location permission</string>
66-
```
67-
68-
For location permissions on iOS see more at: [https://developer.apple.com/documentation/corelocation/requesting_authorization_for_location_services](https://developer.apple.com/documentation/corelocation/requesting_authorization_for_location_services)
6930
## Usage
7031
### Obtain an instance
7132
```dart
@@ -147,6 +108,47 @@ await device.requestMtu(512);
147108
```
148109
Note that iOS will not allow requests of MTU size, and will always try to negotiate the highest possible MTU (iOS supports up to MTU size 185)
149110

111+
## Getting Started
112+
### Change the minSdkVersion for Android
113+
114+
Flutter_blue is compatible only from version 19 of Android SDK so you should change this in **android/app/build.gradle**:
115+
```dart
116+
Android {
117+
defaultConfig {
118+
minSdkVersion: 19
119+
```
120+
### Add permissions for Bluetooth
121+
We need to add the permission to use Bluetooth and access location:
122+
123+
#### **Android**
124+
In the **android/app/src/main/AndroidManifest.xml** let’s add:
125+
126+
```xml
127+
<uses-permission android:name="android.permission.BLUETOOTH" />
128+
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
129+
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
130+
<application
131+
```
132+
#### **IOS**
133+
In the **ios/Runner/Info.plist** let’s add:
134+
135+
```dart
136+
<dict>
137+
<key>NSBluetoothAlwaysUsageDescription</key>
138+
<string>Need BLE permission</string>
139+
<key>NSBluetoothPeripheralUsageDescription</key>
140+
<string>Need BLE permission</string>
141+
<key>NSLocationAlwaysAndWhenInUseUsageDescription</key>
142+
<string>Need Location permission</string>
143+
<key>NSLocationAlwaysUsageDescription</key>
144+
<string>Need Location permission</string>
145+
<key>NSLocationWhenInUseUsageDescription</key>
146+
<string>Need Location permission</string>
147+
```
148+
149+
For location permissions on iOS see more at: [https://developer.apple.com/documentation/corelocation/requesting_authorization_for_location_services](https://developer.apple.com/documentation/corelocation/requesting_authorization_for_location_services)
150+
151+
150152
## Reference
151153
### FlutterBlue API
152154
| | Android | iOS | Description |
@@ -182,6 +184,6 @@ Note that iOS will not allow requests of MTU size, and will always try to negoti
182184
| write | :white_check_mark: | :white_check_mark: | Writes the value of the descriptor. |
183185

184186
## Troubleshooting
185-
### Scanning for service UUID's doesn't return any results
187+
### When I scan using a service UUID filter, it doesn't find any devices.
186188
Make sure the device is advertising which service UUID's it supports. This is found in the advertisement
187189
packet as **UUID 16 bit complete list** or **UUID 128 bit complete list**.

android/build.gradle

+73-57
Original file line numberDiff line numberDiff line change
@@ -1,58 +1,74 @@
1-
group 'com.pauldemarco.flutter_blue'
2-
version '1.0'
3-
4-
buildscript {
5-
repositories {
6-
google()
7-
jcenter()
8-
}
9-
10-
dependencies {
11-
classpath 'com.android.tools.build:gradle:4.1.0'
12-
classpath 'com.google.protobuf:protobuf-gradle-plugin:0.8.15'
13-
}
14-
}
15-
16-
rootProject.allprojects {
17-
repositories {
18-
google()
19-
jcenter()
20-
}
21-
}
22-
23-
apply plugin: 'com.android.library'
24-
apply plugin: 'com.google.protobuf'
25-
26-
android {
27-
compileSdkVersion 30
28-
29-
defaultConfig {
30-
minSdkVersion 19
31-
}
32-
sourceSets {
33-
main {
34-
proto {
35-
srcDir '../protos'
36-
}
37-
}
38-
}
39-
}
40-
41-
protobuf {
42-
protoc {
43-
artifact = 'com.google.protobuf:protoc:3.17.3'
44-
}
45-
generateProtoTasks {
46-
all().each { task ->
47-
task.builtins {
48-
java {
49-
option "lite"
50-
}
51-
}
52-
}
53-
}
54-
}
55-
56-
dependencies {
57-
implementation 'com.google.protobuf:protobuf-javalite:3.17.3'
1+
group 'com.pauldemarco.flutter_blue'
2+
version '1.0'
3+
4+
buildscript {
5+
repositories {
6+
google()
7+
mavenCentral()
8+
}
9+
10+
dependencies {
11+
classpath 'com.android.tools.build:gradle:4.1.0'
12+
classpath 'com.google.protobuf:protobuf-gradle-plugin:0.8.15'
13+
}
14+
}
15+
16+
rootProject.allprojects {
17+
repositories {
18+
google()
19+
mavenCentral()
20+
}
21+
}
22+
23+
apply plugin: 'com.android.library'
24+
apply plugin: 'com.google.protobuf'
25+
26+
android {
27+
compileSdkVersion 31
28+
29+
defaultConfig {
30+
minSdkVersion 19
31+
targetSdkVersion 31
32+
// Use Java 8 language features and APIs
33+
// https://developer.android.com/studio/write/java8-support
34+
multiDexEnabled true
35+
}
36+
37+
compileOptions {
38+
// Use Java 8 language features and APIs
39+
// https://developer.android.com/studio/write/java8-support
40+
// Flag to enable support for the new language APIs
41+
coreLibraryDesugaringEnabled true
42+
// Sets Java compatibility to Java 8
43+
sourceCompatibility JavaVersion.VERSION_1_8
44+
targetCompatibility JavaVersion.VERSION_1_8
45+
}
46+
47+
sourceSets {
48+
main {
49+
proto {
50+
srcDir '../protos'
51+
}
52+
}
53+
}
54+
}
55+
56+
protobuf {
57+
protoc {
58+
artifact = 'com.google.protobuf:protoc:3.17.3'
59+
}
60+
generateProtoTasks {
61+
all().each { task ->
62+
task.builtins {
63+
java {
64+
option "lite"
65+
}
66+
}
67+
}
68+
}
69+
}
70+
71+
dependencies {
72+
coreLibraryDesugaring 'com.android.tools:desugar_jdk_libs:1.1.5'
73+
implementation 'com.google.protobuf:protobuf-javalite:3.17.3'
5874
}

android/src/main/AndroidManifest.xml

+15-6
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,15 @@
1-
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
2-
package="com.pauldemarco.flutter_blue">
3-
<uses-permission android:name="android.permission.BLUETOOTH" />
4-
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
5-
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
6-
</manifest>
1+
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.pauldemarco.flutter_blue">
2+
<!-- New Bluetooth permissions in Android 12
3+
https://developer.android.com/about/versions/12/features/bluetooth-permissions
4+
-->
5+
<!-- Include "neverForLocation" only if you can strongly assert that
6+
your app never derives physical location from Bluetooth scan results. -->
7+
<uses-permission android:name="android.permission.BLUETOOTH_SCAN" android:usesPermissionFlags="neverForLocation" />
8+
<uses-permission android:name="android.permission.BLUETOOTH_ADVERTISE" />
9+
<uses-permission android:name="android.permission.BLUETOOTH_CONNECT" />
10+
11+
<!-- Request legacy Bluetooth permissions on older devices. -->
12+
<uses-permission android:name="android.permission.BLUETOOTH" android:maxSdkVersion="30" />
13+
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" android:maxSdkVersion="30" />
14+
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" android:maxSdkVersion="30" />
15+
</manifest>

0 commit comments

Comments
 (0)