Closed sijanpoudel11 closed 5 months ago
locationAuthorizationRequest: 'Always',
Have you read the API docs for Config.locationAuthorizationRequest
?
I missed it earlier , i saw it now . Thanks ,
Hello @christocracy i tried with these paramerets in Config . It works as expected on IOS but not in Android . Am i missing something here ? On Android the location popup is displayed on every open . I only want to ask for background location for first time .
locationAuthorizationRequest: 'Always', disableLocationAuthorizationAlert: true,
Your Environment
flutter doctor
): [!] Flutter (Channel unknown, 3.7.9, on macOS 14.5 23F79 darwin-arm64, locale en-NP) ! Flutter version 3.7.9 on channel unknown at /Users/sijanpoudel/development/flutter Currently on an unknown channel. Runflutter channel
to switch to an official channel. If that doesn't fix the issue, reinstall Flutter by following instructions at https://flutter.dev/docs/get-started/install. ! Unknown upstream repository. Reinstall Flutter by following instructions at https://flutter.dev/docs/get-started/install. • Framework revision 62bd79521d (1 year, 3 months ago), 2023-03-30 10:59:36 -0700 • Engine revision ec975089ac • Dart version 2.19.6 • DevTools version 2.20.1 • If those were intentional, you can disregard the above warnings; however it is recommended to use "git" directly to perform update checks and upgrades.[✓] Android toolchain - develop for Android devices (Android SDK version 32.1.0-rc1) • Android SDK at /Users/sijanpoudel/Library/Android/sdk • Platform android-34, build-tools 32.1.0-rc1 • ANDROID_HOME = /Users/sijanpoudel/Library/Android/sdk • Java binary at: /Applications/Android Studio.app/Contents/jre/Contents/Home/bin/java • Java version OpenJDK Runtime Environment (build 11.0.11+0-b60-7772763) • All Android licenses accepted.
[✓] Xcode - develop for iOS and macOS (Xcode 15.3) • Xcode at /Applications/Xcode.app/Contents/Developer • Build 15E204a • CocoaPods version 1.14.3
[✓] Chrome - develop for the web • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome
[✓] Android Studio (version 2021.1) • Android Studio at /Applications/Android Studio.app/Contents • Flutter plugin can be installed from: 🔨 https://plugins.jetbrains.com/plugin/9212-flutter • Dart plugin can be installed from: 🔨 https://plugins.jetbrains.com/plugin/6351-dart • Java version OpenJDK Runtime Environment (build 11.0.11+0-b60-7772763)
[✓] VS Code (version 1.90.2) • VS Code at /Applications/Visual Studio Code.app/Contents • Flutter extension version 3.90.0
[✓] Connected device (3 available) • sdk gphone64 arm64 (mobile) • emulator-5554 • android-arm64 • Android 13 (API 33) (emulator) • macOS (desktop) • macos • darwin-arm64 • macOS 14.5 23F79 darwin-arm64 • Chrome (web) • chrome • web-javascript • Google Chrome 126.0.6478.127 ! Error: Browsing on the local area network for iPhone. Ensure the device is unlocked and attached with a cable or associated with the same local area network as this Mac. The device must be opted into Developer Mode to connect wirelessly. (code -27) ! Error: Browsing on the local area network for Touchware’s iPhone. Ensure the device is unlocked and attached with a cable or associated with the same local area network as this Mac. The device must be opted into Developer Mode to connect wirelessly. (code -27)
[✓] HTTP Host Availability • All required HTTP hosts are available
Plugin config: bg.BackgroundGeolocation.addGeofences([ bg.Geofence( notifyOnDwell: true, notifyOnExit: true, identifier: "theatre", radius: 5000, latitude: 27.7165, longitude: 85.2454, notifyOnEntry: true, ), ]).then((bool success) { if (kDebugMode) { print('[addGeofences] success'); } }).catchError((dynamic error) { if (kDebugMode) { print('[addGeofences] FAILURE: $error'); } });
bg.BackgroundGeolocation.onGeofence((bg.GeofenceEvent event) async { if (kDebugMode) { print('[geofence] ${event.identifier}, ${event.action}'); } // bg.Logger.emailLog('sijan.poudel@kotuko.it').then((bool success) { // print('[emailLog] success'); // }).catchError((error) { // print('[emailLog] FAILURE: ${error}'); // });
bg.BackgroundGeolocation.startBackgroundTask().then( (int taskId) async { bg.Location location = await bg.BackgroundGeolocation.getCurrentPosition( samples: 2, persist: false, desiredAccuracy: 10); String? token = await FirebaseMessaging.instance.getToken(); var body = { "firebase_id": await _getId(), "firebase_token": token.toString(), "locale": "en", "latitude": location.coords.latitude.toString(), "longitude": location.coords.longitude.toString(), }; http .post( Uri.parse( "${Data.baseUrl}${Data.baseRoute}/firebase-users", ), body: body) .then( (value) { if (kDebugMode) { print('request geofence body ${body.toString()}'); print('response geofence ${value.request.toString()}'); } bg.BackgroundGeolocation.stopBackgroundTask(taskId); }, ).catchError((dynamic error) { if (kDebugMode) { print("[http test] failed: $error"); } bg.BackgroundGeolocation.stopBackgroundTask(taskId); }); }, ); });
bg.BackgroundGeolocation.ready(bg.Config( locationAuthorizationRequest: 'Always', backgroundPermissionRationale: bg.PermissionRationale( title: "Allow {applicationName} to access to this device's location in the background?", message: "In order to track your activity in the background, please enable {backgroundPermissionOptionLabel} location permission", positiveAction: "Change to {backgroundPermissionOptionLabel}", negativeAction: "Cancel"), // autoSync: true, // maxRecordsToPersist: 1, // url: // "https://teatromassimo-staging.kotuko.rocks/wp-json/teatro-massimo/v1/firebase-users", // params: { // "firebase_id": await _getId(), // "firebase_token": token, // "locale": "en", // "latitude": location.coords.latitude, // "longitude": location.coords.longitude, // }, // batchSync: true, // persistMode: -1, enableHeadless: true, desiredAccuracy: bg.Config.DESIRED_ACCURACY_HIGH, distanceFilter: 1.0, stopOnTerminate: false, startOnBoot: true, debug: false, logLevel: bg.Config.LOG_LEVEL_VERBOSE, )).then((bg.State state) async { // listen only for geofence events var box = Hive.box("userData"); var isFirstOpen = box.get("isFirstOpen", defaultValue: true);
if (isFirstOpen) { await showDialog( barrierDismissible: false, context: context, builder: (context) { return AlertDialog( contentPadding: EdgeInsets.all(width 4), content: Column( crossAxisAlignment: CrossAxisAlignment.end, mainAxisSize: MainAxisSize.min, children: [ buildTitleText( AppLocalizations.of(context)! .translate("splash_prominent_disclosure")!, Colors.black, width), Image.asset("assets/images/map.jpeg"), SizedBox( height: height 2, ), InkWell( onTap: () { box.put("isFirstOpen", false); bg.BackgroundGeolocation.start(); _navigateToHomeScreen(); }, child: Container( decoration: BoxDecoration( color: Colors.blue, borderRadius: BorderRadius.circular(50)), padding: EdgeInsets.symmetric( vertical: height, horizontal: width * 5), child: buildTitleText( AppLocalizations.of(context)! .translate("splash_agree_button")!, Colors.white, width), ), ) ], ), ); }, ); } else { bg.BackgroundGeolocation.start(); _navigateToHomeScreen(); } });
Expected Behavior
After denying the background location permission , it'd not ask again for the permission .
Actual Behavior
Even after denying the always location permission it asks every time the app opens .
Steps to Reproduce
1. 2. 3. 4.
Context
send location data to an api on geofence enter/exit .
Debug logs
Logs
``` PASTE_YOUR_LOGS_HERE ```