Skip to content

Commit

Permalink
Merge pull request #252 from chipweinberger/user/chip/fix-issue-225-a…
Browse files Browse the repository at this point in the history
…ndroid-permissions

[Example] fix issue 225, android permissions
  • Loading branch information
chipweinberger authored Apr 27, 2023
2 parents bc4e276 + 00f1332 commit 5ed330a
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 3 deletions.
4 changes: 2 additions & 2 deletions example/android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ apply plugin: 'com.android.application'
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"

android {
compileSdkVersion 31
compileSdkVersion 33

compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
Expand All @@ -35,7 +35,7 @@ android {
defaultConfig {
applicationId "com.boskokg.flutter_blue_plus_example"
minSdkVersion 19
targetSdkVersion 31
targetSdkVersion 33
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
}
Expand Down
23 changes: 23 additions & 0 deletions example/android/app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,28 @@
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.boskokg.flutter_blue_plus_example">
<!-- Allow Bluetooth -->
<uses-feature
android:name="android.hardware.bluetooth_le"
android:required="true" />
<!-- Request legacy Bluetooth permissions on older devices. -->
<uses-permission android:name="android.permission.BLUETOOTH"
android:maxSdkVersion="30" />
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN"
android:maxSdkVersion="30" />
<!-- Needed only if your app looks for Bluetooth devices.
If your app doesn't use Bluetooth scan results to derive physical
location information, you can strongly assert that your app
doesn't derive physical location. -->
<uses-permission android:name="android.permission.BLUETOOTH_SCAN" />
<!-- Needed only if your app makes the device discoverable to Bluetooth
devices. -->
<uses-permission android:name="android.permission.BLUETOOTH_ADVERTISE" />
<!-- Needed only if your app communicates with already-paired Bluetooth
devices. -->
<uses-permission android:name="android.permission.BLUETOOTH_CONNECT" />
<!-- If your application supports a service and can run on Android 10 (API level 29) or Android 11, you must also declare
the ACCESS_BACKGROUND_LOCATION permission to discover Bluetooth devices. -->
<!-- <uses-permission android:name="android.permission.ACCESS_BACKGROUND_LOCATION" /> -->
<application
android:label="flutter_blue_plus_example"
android:name="${applicationName}"
Expand Down
17 changes: 16 additions & 1 deletion example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,26 @@ import 'dart:math';

import 'package:flutter/material.dart';
import 'package:flutter_blue_plus/flutter_blue_plus.dart';
import 'package:permission_handler/permission_handler.dart';

import 'widgets.dart';

void main() {
runApp(const FlutterBlueApp());

if (Platform.isAndroid) {
WidgetsFlutterBinding.ensureInitialized();
[
Permission.location,
Permission.storage,
Permission.bluetooth,
Permission.bluetoothConnect,
Permission.bluetoothScan
].request().then((status) {
runApp(const FlutterBlueApp());
});
} else {
runApp(const FlutterBlueApp());
}
}

class FlutterBlueApp extends StatelessWidget {
Expand Down
2 changes: 2 additions & 0 deletions example/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ dependencies:

cupertino_icons: ^1.0.2

permission_handler: ^10.2.0

dev_dependencies:
flutter_test:
sdk: flutter
Expand Down

0 comments on commit 5ed330a

Please sign in to comment.