Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
26d9c45
Update FlutterBluePlugin.java
pauloamaral93 May 20, 2020
9836217
Update FlutterBluePlugin.java
pauloamaral93 May 20, 2020
39f6d23
Update FlutterBluePlugin.java
pauloamaral93 May 20, 2020
a5d60d4
Update FlutterBluePlugin.java
pauloamaral93 May 29, 2020
186a39e
Update FlutterBluePlugin.java
pauloamaral93 Dec 21, 2020
259610b
Update bluetooth_device.dart
pauloamaral93 Dec 21, 2020
aedccc3
Update FlutterBluePlugin.java
pauloamaral93 Dec 21, 2020
9e64afe
Update FlutterBluePlugin.java
pauloamaral93 Dec 21, 2020
d181c9e
Update FlutterBluePlugin.java
pauloamaral93 Dec 21, 2020
ce572a1
Update FlutterBluePlugin.java
pauloamaral93 Dec 21, 2020
a6f720c
Update FlutterBluePlugin.java
pauloamaral93 Dec 21, 2020
6ded1d2
Update FlutterBluePlugin.java
pauloamaral93 Dec 21, 2020
3e37511
Update FlutterBluePlugin.java
pauloamaral93 Dec 21, 2020
36142ea
Update FlutterBluePlugin.java
pauloamaral93 Dec 21, 2020
4a1b5fb
Update FlutterBluePlugin.java
pauloamaral93 Dec 22, 2020
548d0d4
Update FlutterBluePlugin.java
pauloamaral93 Dec 22, 2020
2bc7a09
upgrade protobuf
pauloamaral93 Dec 13, 2021
da3f476
Update FlutterBluePlugin.java
pauloamaral93 Jul 22, 2022
5075626
Update FlutterBluePlugin.java
pauloamaral93 Jul 22, 2022
3b5e1a9
Update FlutterBluePlugin.java
pauloamaral93 Jul 22, 2022
e97d83a
Update FlutterBluePlugin.java
pauloamaral93 Jul 22, 2022
e95ff64
Update AdvertisementParser.java
pauloamaral93 Jul 22, 2022
8066d7c
Update FlutterBluePlugin.java
pauloamaral93 Jul 22, 2022
0c34aeb
Update AdvertisementParser.java
pauloamaral93 Jul 22, 2022
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
2 changes: 1 addition & 1 deletion android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ buildscript {

dependencies {
classpath 'com.android.tools.build:gradle:3.5.2'
classpath 'com.google.protobuf:protobuf-gradle-plugin:0.8.7'
classpath 'com.google.protobuf:protobuf-gradle-plugin:0.8.13'
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,12 +76,12 @@ public class FlutterBluePlugin implements MethodCallHandler, RequestPermissionsR
private BluetoothAdapter mBluetoothAdapter;
private final Map<String, BluetoothGatt> mGattServers = new HashMap<>();
private LogLevel logLevel = LogLevel.EMERGENCY;
private Result requestMtuCallback;

// Pending call and result for startScan, in the case where permissions are needed
private MethodCall pendingCall;
private Result pendingResult;
private BroadcastReceiver bondStateBroadcastReceiver = null;
Result resultMTU;

/**
* Plugin registration.
Expand Down Expand Up @@ -351,7 +351,7 @@ public void onReceive(Context context, Intent intent) {
// this part is executed when an exception (in this example InterruptedException) occurs
}
//gattServer = device.connectGatt(registrar.activity(), false, mGattCallback);
gattServer = device.connectGatt(registrar.activity(), options.getAndroidAutoConnect(), mGattCallback, BluetoothDevice.TRANSPORT_AUTO, BluetoothDevice.PHY_LE_CODED);
gattServer = device.connectGatt(registrar.activity(), options.getAndroidAutoConnect(), mGattCallback, BluetoothDevice.TRANSPORT_LE);
} else {
try
{
Expand All @@ -377,6 +377,7 @@ public void onReceive(Context context, Intent intent) {
if(gattServer != null) {
gattServer.disconnect();
gattServer.close();
gattServer = null;
}
result.success(null);
break;
Expand Down Expand Up @@ -427,9 +428,9 @@ public void onReceive(Context context, Intent intent) {
}
break;
}

case "requestMtu": {

case "mtu":
{
Integer size = call.argument("size");
String remoteId = call.argument("remoteId");
if (size == null) {
Expand All @@ -446,14 +447,46 @@ public void onReceive(Context context, Intent intent) {
gattServer = mGattServers.get(remoteId);
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {

boolean re = gattServer.requestMtu(size);
Log.i(TAG, "New MTU status is " + re);
boolean re = gattServer.requestMtu(2000);
Log.i(TAG, "MTU status is " + re);
if(re) {
requestMtuCallback = result;
//result.success(true);
result.success(true);
} else {
result.error("requestMtu", "gatt.requestMtu returned false", null);
result.error("getMtu", "gatt.requestMtu returned false", null);
}
} else {
result.error("gettMtu", "Only supported on devices >= API 21 (Lollipop). This device == " + Build.VERSION.SDK_INT, null);
}
} catch(Exception e) {
result.error("getMtu", e.getMessage(), e);
}
break;
}



case "requestMtu": {

Integer size = call.argument("size");
String remoteId = call.argument("remoteId");
if (size == null) {
result.error(
"ValueError",
"\"size\" cannot be null!",
null
);
return;
}

BluetoothGatt gattServer;
try {
gattServer = mGattServers.get(remoteId);
if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
resultMTU = result;
gattServer.requestMtu(size);



} else {
result.error("requestMtu", "Only supported on devices >= API 21 (Lollipop). This device == " + Build.VERSION.SDK_INT, null);
}
Expand Down Expand Up @@ -1134,29 +1167,33 @@ public void onMtuChanged(BluetoothGatt gatt, int mtu, int status) {
log(LogLevel.DEBUG, "[onMtuChanged] mtu: " + mtu + " status: " + status);



if (status == BluetoothGatt.GATT_SUCCESS) {
registrar.activity().runOnUiThread(
new Runnable() {
@Override
public void run() {
try
{
requestMtuCallback.success(mtu);
}
catch(InterruptedException e)
{
// this part is executed when an exception (in this example InterruptedException) occurs
}}});


} else {
requestMtuCallback.error("error", "gatt.requestMtu failed", null);
}
requestMtuCallback = null;

if (status == BluetoothGatt.GATT_SUCCESS) {
registrar.activity().runOnUiThread(
new Runnable() {
@Override
public void run() {
resultMTU.success(true);

}
});
} else {
registrar.activity().runOnUiThread(
new Runnable() {
@Override
public void run() {
resultMTU.error("requestMtu", "gatt.requestMtu returned false", null);

}
});


}


//...




}
};

Expand Down
7 changes: 7 additions & 0 deletions lib/src/bluetooth_device.dart
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,13 @@ class BluetoothDevice {
});
}

Future<bool> getMtu(int size) async {
return await FlutterBlue.instance._channel.invokeMethod("mtu", {
"size": size,
"remoteId": id.toString(),
});
}

Future<bool> bondDevice() async {
return await FlutterBlue.instance._channel.invokeMethod("bondDevice", {
"remoteId": id.toString(),
Expand Down