Comments (11)
I remember encountering that issue when first started using flutter blue. I don't remember how I fixed it though :(. This time around we should make sure the solution is documented.
from flutter_blue.
OK, found the culprit. As it turns out, since the 13 of december, gradle4 is used. I had to update the gradle build settings according to https://github.com/flutter/flutter/wiki/Updating-Flutter-projects-to-Gradle-4.1-and-Android-Studio-Gradle-plugin-3.0.1
Be sure to do a flutter package get in the example folder after you have done the changes so that the flutter_blue plugin is also compiled to this version. First I did not do that and got a crash of the example app.
I'll send a PR for the changes I did to get the example running.
from flutter_blue.
I solved that by adding the simple_permissions package (https://pub.dartlang.org/packages/simple_permissions#-example-tab-)
a) import simple_permissions on pubspec.yaml (simple_permissions: "^0.1.0" )
b) add permissions on manifest
c) add code to ask for permission
on _FlutterBlueAppState call
updatePermission() async {
Permission permission = Permission.AccessCoarseLocation;
if (await SimplePermissions.checkPermission(permission)) {
isPermissionGranted = true;
} else {
if (await SimplePermissions.requestPermission(permission)) {
isPermissionGranted = true;
} else {
isPermissionGranted = false;
}
}
print("Bluetooth coarse location granted??? $isPermissionGranted");
}
from flutter_blue.
The reason the example works in the example app in this repo is that its gradle file is missing targetSdkVersion 26
thus using the old permissions model.
I'm working on a patch.
from flutter_blue.
#49 simply updates gradle file making the example app break, followed by updating example app to fix it.
A following possible patch would be include permission check/request in relevant api methods such as scan / advertise. I like that approach because it makes it simpler for people adopting the library.
Good practice for android says we should tell the user we're going to ask for a permission and why we want it; only then make request. We can make the automatically ask for permission the default, and if opting out dev should simply do the checking before calling scan.
from flutter_blue.
Hi @pauldemarco,
I understand if you're busy, but can you give us a hint if you would consider this issue? It's a simple PR without any updates in a while, and there may be other more complex PRs as well (such as #55 and #53) that are about as old.
Is there something missing from this issue that I can provide to move the PR forward?
from flutter_blue.
Hi @fmatosqg, sorry for the delay, I have some time set aside to look into this next week.
Handling Android permissions within FlutterBlue is something that will take some consideration. As flutter continues to grow and be available on more platforms, I'd like to avoid adding non-bluetooth functionality, like permission requesting . I think outsourcing this to a dedicated "permissions" plugin, like the one mentioned, would be a better solution.
from flutter_blue.
I'm thinking the developer can get the adapter state using FlutterBlue, and if it comes back as unauthorized, can then reach out to a third party plugin that handles permissions.
I'm open to hearing any thoughts on this
from flutter_blue.
from flutter_blue.
I think the change to the example build gradle is necessary to match what most people will have now and what google will enforce by november. And this change will make the example break.
I feel the example should keep being completely self enclosed, to the point of being useful for people who have never looked at mobile permissions before. The bluetooth api has already many steps, and I think there will be a handful of developers unaware or forgetting the very first step - granting permissions - increasing the apparent difficulty of dealing with bluetooth.
In this sense I only see 2 options, a) adding code on both native sides to check for permissions and return appropriate errors to user via dart, or b) depend on an existing dart library either at sample level or enclosed in flutter_blue library.
Between a and b I'd definitely go with b, or else we'd be reinventing the wheel. On option b I can see pros and cons, but I don't have a strong preference either way.
BTW the recommended approach for permissions is asking/checking them proactively before starting using methods. That will feel more intuitive to people coming from native.
I'm also open for thoughts.
from flutter_blue.
Runtime permissions have been added to Android side with minimal code.
If permissions are needed for a scan, they will be automatically requested from the user. If permissions are denied, it will error out and cancel scanning.
This now targets the latest android API, and maintains backwards compatibility all the way to android API 18.
Note: Since ACCESS_COARSE_LOCATION or ACCESS_FINE_LOCATION can be used for Bluetooth scanning, I chose the lesser of the two, ACCESS_COARSE_LOCATION.
from flutter_blue.
Related Issues (20)
- There is a problem compiling the library with Flutter 3.7.12 with Gradle 8 HOT 4
- Flutter_blue_plus scan not working when the device screen is off
- Initiating ble channel upon collision detection to trigger alarm HOT 1
- Race condition between Connect timeout and a successful connection leaving active connection stranded HOT 2
- MissingPluginException on device.connect() HOT 2
- upgrade your rxdart library to latest, its conflicting with other libraries because of older version HOT 1
- Gamepanel gp isn't null buy I still get a null pointer exception when I call speak()
- 🚨🚨🚨 [Public Service Announcement] flutter_blue_plus is the successor to this library 🚨🚨🚨
- Command execution not working?
- C:\Users\ABS\AppData\Local\Pub\Cache\hosted\pub.dev\flutter_blue_plus-1.15.2\android\src\main\java\com\boskokg\flutter_blue_plus\FlutterBluePlusPlugin.java uses or overrides a deprecated API.
- Help to resolve this error HOT 3
- ITMS-90863: Apple silicon Macs support issue HOT 3
- App crash when try readValue on android but on windows work fine
- 🚨🚨🚨 [Public Service Announcement] flutter_blue is deprecated❗Use flutter_blue_plus 🚨🚨🚨 HOT 1
- reading return value from
- 🚨🚨🚨 [Public Service Announcement] flutter_blue is deprecated❗Use flutter_blue_plus 🚨🚨🚨
- Could not resolve all files for configuration ':lib-transparency-api:protobufToolsLocator_protoc'. HOT 1
- 🚨🚨🚨 [Public Service Announcement] flutter_blue is deprecated❗Use flutter_blue_plus 🚨🚨🚨
- Execution failed for task ':flutter_blue:generateDebugProto'. HOT 1
- 🚨🚨🚨 [Public Service Announcement] flutter_blue is deprecated❗Use flutter_blue_plus 🚨🚨🚨
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from flutter_blue.