Baseflow / flutter-geolocator

Android and iOS Geolocation plugin for Flutter
https://baseflow.com/
MIT License
1.24k stars 652 forks source link

Foreground notification data passed to ForegroundConfig are not being displayed #1060

Open nayefmazen opened 2 years ago

nayefmazen commented 2 years ago

šŸ› Bug Report

I am passing a custom foreground config in locationSettings for android, basically I am changing the notification title and notification text. However, the notification title and text are not changing to the values being passed. Here is a code sample of what I am doing:

setting the location settings:

 late LocationSettings _locationSettings;
  LocationSettings get locationSettings => _locationSettings;

  Future<void> setupLocationServiceStatus() async {
    await refreshStatuses();
    if (defaultTargetPlatform == TargetPlatform.android) {
      _locationSettings = AndroidSettings(
        accuracy: LocationAccuracy.high,
        intervalDuration: const Duration(seconds: 5),
        foregroundNotificationConfig: ForegroundNotificationConfig(
          notificationTitle: LOCATION_NOTIFICATION_TITLE,
          notificationText: LOCATION_NOTIFICATION_DESCRIPTION,
        ),
      );
    } else if (defaultTargetPlatform == TargetPlatform.iOS) {
      _locationSettings = AppleSettings(
        accuracy: LocationAccuracy.high,
        showBackgroundLocationIndicator: true,
      );
    }
  }

subscribing to the get position stream:

locationStreamSubscription = Geolocator.getPositionStream(
      locationSettings: LocationService.getInstance().locationSettings,
    ).listen((Position? position) async {
      if (position == null) return;
      currentLocation = LatLng(position.latitude, position.longitude);
      MainServicesStream.addLocationEvent(
        UserMovedMapEvent(currentLocation!),
      );
    });

Expected behavior

expected behaviour is to update the notification title and text to the data being passed

Reproduction steps

  1. give all the necessary permissions
  2. ensure location service is enabled on the phone
  3. subscribe to GeoLocator.getPositionStream and pass the location settings with custom foreground config
  4. stream is working fine but the foreground notification not showing the details that have been passed in step 3

Configuration

I am testing on a samsung s21 FE with android 12 flutter details:

[āœ“] Flutter (Channel stable, 3.0.0, on macOS 12.1 21C52 darwin-arm, locale en-GB)
    ā€¢ Flutter version 3.0.0 at /Users/nayefradwi/flutter
    ā€¢ Upstream repository https://github.com/flutter/flutter.git
    ā€¢ Framework revision ee4e09cce0 (5 days ago), 2022-05-09 16:45:18 -0700
    ā€¢ Engine revision d1b9a6938a
    ā€¢ Dart version 2.17.0
    ā€¢ DevTools version 2.12.2

Version: 8.2.1

Platform:

flodaniel commented 1 year ago

Hi @nayefmazen, I am also just setting up the plugin. I discovered that a wrong notificationIcon property caused my strings not being shown. Maybe the default icon that is set by the plugin is not present in your android folder?

zirg41 commented 11 months ago

@nayefmazen have u found solutions to this issue?

ryohey commented 2 weeks ago

I faced a similar problem with foreground notifications not showing up in release builds, but I solved it by putting keep.xml in android/app/src/main/res. This was caused by Flutter deleting inside the drawable at build time.

<?xml version="1.0" encoding="utf-8"?>
<resources xmlns:tools="http://schemas.android.com/tools"
    tools:keep="@drawable/*" />

related https://github.com/flutter/flutter/issues/102455 https://github.com/ryanheise/audio_service/issues/631