Commit 412391a5 by florissmit1 Committed by GitHub

Android 12 (API 31) deprecation error fix when building appbundle (#662)

* BluetoothAdapter deprecation fix

* Updated the CHANGELOG.md and the pubspec.yaml

* Changes to the build.gradle

* Update permission_handler/android/src/main/java/com/baseflow/permissionhandler/ServiceManager.java

Co-authored-by: Maurits van Beusekom <maurits@vnbskm.nl>

* Added the documentation for public members

Co-authored-by: floris smit <florissmit@floriss-Air.localdomain>
Co-authored-by: Maurits van Beusekom <maurits@vnbskm.nl>
parent 9ebf277e
## 8.1.5
* Android: Fixed deprecation warnings/errors when `compileSdkVersion` was set to 31 (Android S/12).
## 8.1.4+2 ## 8.1.4+2
* iOS: fixed memory error that occurred on iOS 12.2 and below (see issue [#638](https://github.com/Baseflow/flutter-permission-handler/issues/638)). * iOS: fixed memory error that occurred on iOS 12.2 and below (see issue [#638](https://github.com/Baseflow/flutter-permission-handler/issues/638)).
......
package com.baseflow.permissionhandler; package com.baseflow.permissionhandler;
import static android.content.Context.BLUETOOTH_SERVICE;
import android.bluetooth.BluetoothAdapter; import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothManager;
import android.content.Context; import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.content.pm.PackageManager; import android.content.pm.PackageManager;
...@@ -45,7 +48,7 @@ final class ServiceManager { ...@@ -45,7 +48,7 @@ final class ServiceManager {
return; return;
} }
if(permission == PermissionConstants.PERMISSION_GROUP_BLUETOOTH){ if(permission == PermissionConstants.PERMISSION_GROUP_BLUETOOTH){
final int serviceStatus = isBluetoothServiceEnabled() final int serviceStatus = isBluetoothServiceEnabled(context)
? PermissionConstants.SERVICE_STATUS_ENABLED ? PermissionConstants.SERVICE_STATUS_ENABLED
: PermissionConstants.SERVICE_STATUS_DISABLED; : PermissionConstants.SERVICE_STATUS_DISABLED;
...@@ -147,9 +150,16 @@ final class ServiceManager { ...@@ -147,9 +150,16 @@ final class ServiceManager {
Settings.Secure.LOCATION_PROVIDERS_ALLOWED); Settings.Secure.LOCATION_PROVIDERS_ALLOWED);
return !TextUtils.isEmpty(locationProviders); return !TextUtils.isEmpty(locationProviders);
} }
// Suppress deprecation warnings since its purpose is to support to be backwards compatible with
private boolean isBluetoothServiceEnabled() { // pre S versions of Android
final BluetoothAdapter bluetoothAdapter = BluetoothAdapter.getDefaultAdapter(); @SuppressWarnings("deprecation")
return bluetoothAdapter.isEnabled(); private boolean isBluetoothServiceEnabled(Context context) {
if (android.os.Build.VERSION.SDK_INT < android.os.Build.VERSION_CODES.JELLY_BEAN_MR2) {
return BluetoothAdapter.getDefaultAdapter().isEnabled();
}
BluetoothManager manager = (BluetoothManager) context.getSystemService(BLUETOOTH_SERVICE);
final BluetoothAdapter adapter = manager.getAdapter();
return adapter.isEnabled();
} }
} }
...@@ -18,6 +18,7 @@ final MaterialColor themeMaterialColor = ...@@ -18,6 +18,7 @@ final MaterialColor themeMaterialColor =
/// A Flutter application demonstrating the functionality of this plugin /// A Flutter application demonstrating the functionality of this plugin
class PermissionHandlerWidget extends StatefulWidget { class PermissionHandlerWidget extends StatefulWidget {
/// Create a page containing the functionality of this plugin
static ExamplePage createPage() { static ExamplePage createPage() {
return ExamplePage( return ExamplePage(
Icons.location_on, (context) => PermissionHandlerWidget()); Icons.location_on, (context) => PermissionHandlerWidget());
...@@ -62,8 +63,9 @@ class _PermissionHandlerWidgetState extends State<PermissionHandlerWidget> { ...@@ -62,8 +63,9 @@ class _PermissionHandlerWidgetState extends State<PermissionHandlerWidget> {
} }
} }
/// Permission widget containing information about the passed [Permission]
class PermissionWidget extends StatefulWidget { class PermissionWidget extends StatefulWidget {
/// Constructs a [PermissionWidget] for the supplied [Permission]. /// Constructs a [PermissionWidget] for the supplied [Permission]
const PermissionWidget(this._permission); const PermissionWidget(this._permission);
final Permission _permission; final Permission _permission;
......
name: permission_handler name: permission_handler
description: Permission plugin for Flutter. This plugin provides a cross-platform (iOS, Android) API to request and check permissions. description: Permission plugin for Flutter. This plugin provides a cross-platform (iOS, Android) API to request and check permissions.
version: 8.1.4+2 version: 8.1.5
homepage: https://github.com/baseflowit/flutter-permission-handler homepage: https://github.com/baseflowit/flutter-permission-handler
flutter: flutter:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment