Background service support on Android (#215)

* - Added support for BLE scanning from background services on Android.
- Enhanced `PermissionHandler` to be activity-aware, allowing silent success for already granted permissions when no activity is available.
- Updated README with best practices for requesting permissions in foreground before background operations.

* Simplify implementation
This commit is contained in:
Foti Dim
2026-02-04 20:12:12 +02:00
committed by GitHub
parent bcf65e4573
commit ceda9a31f7
5 changed files with 62 additions and 8 deletions
@@ -209,7 +209,10 @@ class UniversalBlePigeonChannel extends UniversalBlePlatform {
}
Future<void> _ensureInitialized(PlatformConfig? platformConfig) async {
// Check bluetooth availability on Apple and Android
// Request permissions on Apple and Android
// On Android: If activity is available, requests permissions if needed.
// If activity is not available (e.g., ForegroundTask), succeeds
// if permissions are already granted, fails otherwise.
if (defaultTargetPlatform == TargetPlatform.android ||
defaultTargetPlatform == TargetPlatform.iOS ||
defaultTargetPlatform == TargetPlatform.macOS) {