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

flutter_blue_plus\FlutterBluePlusPlugin.java uses or overrides a deprecated API #46

Closed
cvanbeek13 opened this issue Apr 20, 2022 · 6 comments

Comments

@cvanbeek13
Copy link

When I run flutter build apk, I get the following warning:

Note: D:\Users\cvanbeek\installs\flutter\.pub-cache\hosted\pub.dartlang.org\flutter_blue_plus-1.1.3\android\src\main\java\com\boskokg\flutter_blue_plus\FlutterBluePlusPlugin.java uses or overrides a deprecated API.
Note: Recompile with -Xlint:deprecation for details.

Version Info:

flutter_blue_plus: 1.1.3

Flutter:

Flutter 2.10.4 • channel stable • https://github.com/flutter/flutter.git
Framework • revision c860cba910 (4 weeks ago) • 2022-03-25 00:23:12 -0500
Engine • revision 57d3bac3dd
Tools • Dart 2.16.2 • DevTools 2.9.2
@sqcsabbey
Copy link
Contributor

It looks like this project is using Android's BluetoothAdapter startLeScan and stopLeScan methods, which are deprecated; here are the warnings with the deprecated linting enabled:

/Users/csabbey/homebrew/Caskroom/flutter/2.10.3/flutter/.pub-cache/hosted/pub.dartlang.org/flutter_blue_plus-1.1.3/android/src/main/java/com/boskokg/flutter_blue_plus/FlutterBluePlusPlugin.java:904: warning: [deprecation] startLeScan(UUID[],LeScanCallback) in BluetoothAdapter has been deprecated
    boolean success = mBluetoothAdapter.startLeScan(uuids, getScanCallback18());
                                       ^
/Users/csabbey/homebrew/Caskroom/flutter/2.10.3/flutter/.pub-cache/hosted/pub.dartlang.org/flutter_blue_plus-1.1.3/android/src/main/java/com/boskokg/flutter_blue_plus/FlutterBluePlusPlugin.java:909: warning: [deprecation] stopLeScan(LeScanCallback) in BluetoothAdapter has been deprecated
    mBluetoothAdapter.stopLeScan(getScanCallback18());
                     ^

This SO answer says to use BluetoothLeScanner instead, which is available since API level 21 (Android 5.0).

@MrCsabaToth
Copy link
Contributor

Oh ok, currently my minSDK level is 19, so bumping that to 24 would exclude some of my users. Although I know that it could get rid of some spurious Bluetooth behavior if I'd support higher min SDK level. I wish support libraries would port back the newer scanner to 19. Although that's ancient, KitKat. Usually iOS users who really want my app dig up some dusty slow crappy old tablet from a bottom of a drawer and those sometimes are KitKat. PITA.

@boskokg boskokg closed this as completed Jul 23, 2022
@MrCsabaToth
Copy link
Contributor

It's a question though when will the currently used API deprecate. Having a plan to transition to BluetoothLeScanner. I accidentally wrote API level 24, I meant 21 and that's not so far from 19.

@MrCsabaToth
Copy link
Contributor

Here is a way to use both: https://stackoverflow.com/a/39412791/292502

private BluetoothAdapter bluetoothAdapter;
private BluetoothAdapter.LeScanCallback leScanCallback;
private ScanCallback scanCallback;
private ScanSettings scanSetting;

// Check before call the function
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
    bluetoothAdapter.getBluetoothLeScanner().startScan(filterList, scanSetting, scanCallback);
} else {
    bluetoothAdapter.startLeScan(leScanCallback);
}

@boskokg
Copy link
Owner

boskokg commented Jul 23, 2022

Actually we are checking before call:

  if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
    startScan21(settings);
  } else {
    startScan18(settings);
  }

Thing is that we cannot write all that logic to single line and extracting to methods startScan21 and startScan18 makes this false-positive warning.

@MrCsabaToth
Copy link
Contributor

Actually we are checking before call:

Oooh! That's great to know! Sorry for not checking the source code!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants