Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

App crashed with targetSdkVersion 34, Error: One of RECEIVER_EXPORTED or RECEIVER_NOT_EXPORTED should be specified #200

Open
LukasP94 opened this issue Feb 7, 2024 · 27 comments

Comments

@LukasP94
Copy link

LukasP94 commented Feb 7, 2024

Hello,

when app is targeting SDK 34, then app crashes as soon as BackgroundLocation.startLocationService() is called. See stacktrace

D/AndroidRuntime( 8320): Shutting down VM
E/AndroidRuntime( 8320): FATAL EXCEPTION: main
E/AndroidRuntime( 8320): Process: com.company.myapp.dev, PID: 8320
E/AndroidRuntime( 8320): java.lang.RuntimeException: Unable to create service com.almoullim.background_location.LocationUpdatesService: java.lang.SecurityException: com.company.myapp.dev: One of RECEIVER_EXPORTED or RECEIVER_NOT_EXPORTED should be specified when a receiver isn't being registered exclusively for system broadcasts
E/AndroidRuntime( 8320): at android.app.ActivityThread.handleCreateService(ActivityThread.java:4684)
E/AndroidRuntime( 8320): at android.app.ActivityThread.-$$Nest$mhandleCreateService(Unknown Source:0)
E/AndroidRuntime( 8320): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2269)
E/AndroidRuntime( 8320): at android.os.Handler.dispatchMessage(Handler.java:106)
E/AndroidRuntime( 8320): at android.os.Looper.loopOnce(Looper.java:205)
E/AndroidRuntime( 8320): at android.os.Looper.loop(Looper.java:294)
E/AndroidRuntime( 8320): at android.app.ActivityThread.main(ActivityThread.java:8194)
E/AndroidRuntime( 8320): at java.lang.reflect.Method.invoke(Native Method)
E/AndroidRuntime( 8320): at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:552)
E/AndroidRuntime( 8320): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:971)
E/AndroidRuntime( 8320): Caused by: java.lang.SecurityException: com.company.myapp.dev: One of RECEIVER_EXPORTED or RECEIVER_NOT_EXPORTED should be specified when a receiver isn't being registered exclusively for system broadcasts
E/AndroidRuntime( 8320): at android.os.Parcel.createExceptionOrNull(Parcel.java:3057)
E/AndroidRuntime( 8320): at android.os.Parcel.createException(Parcel.java:3041)
E/AndroidRuntime( 8320): at android.os.Parcel.readException(Parcel.java:3024)
E/AndroidRuntime( 8320): at android.os.Parcel.readException(Parcel.java:2966)
E/AndroidRuntime( 8320): at android.app.IActivityManager$Stub$Proxy.registerReceiverWithFeature(IActivityManager.java:5684)
E/AndroidRuntime( 8320): at android.app.ContextImpl.registerReceiverInternal(ContextImpl.java:1852)
E/AndroidRuntime( 8320): at android.app.ContextImpl.registerReceiver(ContextImpl.java:1792)
E/AndroidRuntime( 8320): at android.app.ContextImpl.registerReceiver(ContextImpl.java:1780)
E/AndroidRuntime( 8320): at android.content.ContextWrapper.registerReceiver(ContextWrapper.java:755)
E/AndroidRuntime( 8320): at com.almoullim.background_location.LocationUpdatesService.onCreate(LocationUpdatesService.kt:154)
E/AndroidRuntime( 8320): at android.app.ActivityThread.handleCreateService(ActivityThread.java:4671)
E/AndroidRuntime( 8320): ... 9 more
E/AndroidRuntime( 8320): Caused by: android.os.RemoteException: Remote stack trace:
E/AndroidRuntime( 8320): at com.android.server.am.ActivityManagerService.registerReceiverWithFeature(ActivityManagerService.java:13995)
E/AndroidRuntime( 8320): at android.app.IActivityManager$Stub.onTransact(IActivityManager.java:2570)
E/AndroidRuntime( 8320): at com.android.server.am.ActivityManagerService.onTransact(ActivityManagerService.java:2763)
E/AndroidRuntime( 8320): at android.os.Binder.execTransactInternal(Binder.java:1332)
E/AndroidRuntime( 8320): at android.os.Binder.execTransact(Binder.java:1278)
E/AndroidRuntime( 8320):

Thank you for advance for fixing that!

Copy link

github-actions bot commented Mar 9, 2024

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days.

@github-actions github-actions bot added the stale label Mar 9, 2024
@dharmik-dalwadi-seaflux

@LukasP94 I was facing the same issue. I have fixed that into this forked version
https://github.com/dharmik-dalwadi-seaflux/background_location

Usage

  background_location: 
    git:
      url: https://github.com/dharmik-dalwadi-seaflux/background_location.git
      ref: master

@github-actions github-actions bot removed the stale label Mar 14, 2024
@sisalik1
Copy link

sisalik1 commented Apr 9, 2024

@LukasP94 I was facing the same issue. I have fixed that into this forked version https://github.com/dharmik-dalwadi-seaflux/background_location

Usage

  background_location: 
    git:
      url: https://github.com/dharmik-dalwadi-seaflux/background_location.git
      ref: master

This problem was cleared, but it also appears to have another problem, but all the permissions are given by the user:

E/AndroidRuntime(22305): FATAL EXCEPTION: main
E/AndroidRuntime(22305): Process: xxx.xxxxxx.xxx, PID: 22305
E/AndroidRuntime(22305): java.lang.RuntimeException: Unable to create service com.almoullim.background_location.LocationUpdatesService: java.lang.SecurityException: Starting FGS with type location callerApp=ProcessRecord{e70f782 22305:xxx.xxxxxx.xxx/u0a447} targetSDK=34 requires permissions: all of the permissions allOf=true [android.permission.FOREGROUND_SERVICE_LOCATION] any of the permissions allOf=false [android.permission.ACCESS_COARSE_LOCATION, android.permission.ACCESS_FINE_LOCATION] and the app must be in the eligible state/exemptions to access the foreground only permission
E/AndroidRuntime(22305): at android.app.ActivityThread.handleCreateService(ActivityThread.java:5111)
E/AndroidRuntime(22305): at android.app.ActivityThread.-$$Nest$mhandleCreateService(Unknown Source:0)
E/AndroidRuntime(22305): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2506)
E/AndroidRuntime(22305): at android.os.Handler.dispatchMessage(Handler.java:106)
E/AndroidRuntime(22305): at android.os.Looper.loopOnce(Looper.java:230)
E/AndroidRuntime(22305): at android.os.Looper.loop(Looper.java:319)
E/AndroidRuntime(22305): at android.app.ActivityThread.main(ActivityThread.java:8893)
E/AndroidRuntime(22305): at java.lang.reflect.Method.invoke(Native Method)
E/AndroidRuntime(22305): at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:608)
E/AndroidRuntime(22305): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1103)
E/AndroidRuntime(22305): Caused by: java.lang.SecurityException: Starting FGS with type location callerApp=ProcessRecord{e70f782 22305:xxx.xxxxxx.xxx/u0a447} targetSDK=34 requires permissions: all of the permissions allOf=true [android.permission.FOREGROUND_SERVICE_LOCATION] any of the permissions allOf=false [android.permission.ACCESS_COARSE_LOCATION, android.permission.ACCESS_FINE_LOCATION] and the app must be in the eligible state/exemptions to access the foreground only permission
E/AndroidRuntime(22305): at android.os.Parcel.createExceptionOrNull(Parcel.java:3069)
E/AndroidRuntime(22305): at android.os.Parcel.createException(Parcel.java:3053)
E/AndroidRuntime(22305): at android.os.Parcel.readException(Parcel.java:3036)
E/AndroidRuntime(22305): at android.os.Parcel.readException(Parcel.java:2978)
E/AndroidRuntime(22305): at android.app.IActivityManager$Stub$Proxy.setServiceForeground(IActivityManager.java:7214)
E/AndroidRuntime(22305): at android.app.Service.startForeground(Service.java:775)
E/AndroidRuntime(22305): at com.almoullim.background_location.LocationUpdatesService.updateNotification(LocationUpdatesService.kt:177)
E/AndroidRuntime(22305): at com.almoullim.background_location.LocationUpdatesService.onCreate(LocationUpdatesService.kt:156)
E/AndroidRuntime(22305): at android.app.ActivityThread.handleCreateService(ActivityThread.java:5098)
E/AndroidRuntime(22305): ... 9 more

Copy link

This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days.

@lukaskurz
Copy link
Contributor

I made a fork here:

https://github.com/lukaskurz/background_location/tree/master

This fork contains fixes for both the issues mentioned by @LukasP94 as well as the issues found in the other fork described by @sisalik1 .

I tested it on emulator with API 34 as well as API 29/30 on device, so it should work with both before/after API 33 changes.

@nzackoya
Copy link

Same here

@AfiqMutaz
Copy link

I made a fork here:

https://github.com/lukaskurz/background_location/tree/master

This fork contains fixes for both the issues mentioned by @LukasP94 as well as the issues found in the other fork described by @sisalik1 .

I tested it on emulator with API 34 as well as API 29/30 on device, so it should work with both before/after API 33 changes.

@lukaskurz I tried using your fork on my Samsung A52s (API 34), but it did not compile,

e: file:///C:/Users/pc-name/AppData/Local/Pub/Cache/git/background_location-55c7845ce11b72975ab529d2b2fdf1c982fa01a8/android/src/main/kotlin/com/almoullim/background_location/BackgroundLocationService.kt:27:41 Const 'val' initializer should be a constant value
e: file:///C:/Users/pc-name/AppData/Local/Pub/Cache/git/background_location-55c7845ce11b72975ab529d2b2fdf1c982fa01a8/android/src/main/kotlin/com/almoullim/background_location/BackgroundLocationService.kt:27:44 Unresolved reference: BackgroundLocationPlugin
e: file:///C:/Users/pc-name/AppData/Local/Pub/Cache/git/background_location-55c7845ce11b72975ab529d2b2fdf1c982fa01a8/android/src/main/kotlin/com/almoullim/background_location/BackgroundLocationService.kt:96:17 Unresolved reference: Utils
e: file:///C:/Users/pc-name/AppData/Local/Pub/Cache/git/background_location-55c7845ce11b72975ab529d2b2fdf1c982fa01a8/android/src/main/kotlin/com/almoullim/background_location/BackgroundLocationService.kt:207:19 Unresolved reference: BackgroundLocationPlugin
e: file:///C:/Users/pc-name/AppData/Local/Pub/Cache/git/background_location-55c7845ce11b72975ab529d2b2fdf1c982fa01a8/android/src/main/kotlin/com/almoullim/background_location/BackgroundLocationService.kt:211:19 Unresolved reference: BackgroundLocationPlugin
e: file:///C:/Users/pc-name/AppData/Local/Pub/Cache/git/background_location-55c7845ce11b72975ab529d2b2fdf1c982fa01a8/android/src/main/kotlin/com/almoullim/background_location/BackgroundLocationService.kt:241:15 Unresolved reference: BackgroundLocationPlugin
e: file:///C:/Users/pc-name/AppData/Local/Pub/Cache/git/background_location-55c7845ce11b72975ab529d2b2fdf1c982fa01a8/android/src/main/kotlin/com/almoullim/background_location/BackgroundLocationService.kt:244:51 Unresolved reference: BackgroundLocationPlugin
e: file:///C:/Users/pc-name/AppData/Local/Pub/Cache/git/background_location-55c7845ce11b72975ab529d2b2fdf1c982fa01a8/android/src/main/kotlin/com/almoullim/background_location/LocationUpdatesService.kt:168:9 Unresolved reference: Utils
e: file:///C:/Users/pc-name/AppData/Local/Pub/Cache/git/background_location-55c7845ce11b72975ab529d2b2fdf1c982fa01a8/android/src/main/kotlin/com/almoullim/background_location/LocationUpdatesService.kt:177:13 Unresolved reference: Utils
e: file:///C:/Users/pc-name/AppData/Local/Pub/Cache/git/background_location-55c7845ce11b72975ab529d2b2fdf1c982fa01a8/android/src/main/kotlin/com/almoullim/background_location/LocationUpdatesService.kt:252:13 Unresolved reference: Utils
e: file:///C:/Users/pc-name/AppData/Local/Pub/Cache/git/background_location-55c7845ce11b72975ab529d2b2fdf1c982fa01a8/android/src/main/kotlin/com/almoullim/background_location/LocationUpdatesService.kt:255:13 Unresolved reference: Utils

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':background_location:compileDebugKotlin'.
> A failure occurred while executing org.jetbrains.kotlin.compilerRunner.GradleCompilerRunnerWithWorkers$GradleKotlinCompilerWorkAction
   > Compilation error. See log for more details

@jacob6838
Copy link

I made a fork here:
https://github.com/lukaskurz/background_location/tree/master
This fork contains fixes for both the issues mentioned by @LukasP94 as well as the issues found in the other fork described by @sisalik1 .
I tested it on emulator with API 34 as well as API 29/30 on device, so it should work with both before/after API 33 changes.

@lukaskurz I tried using your fork on my Samsung A52s (API 34), but it did not compile,

e: file:///C:/Users/pc-name/AppData/Local/Pub/Cache/git/background_location-55c7845ce11b72975ab529d2b2fdf1c982fa01a8/android/src/main/kotlin/com/almoullim/background_location/BackgroundLocationService.kt:27:41 Const 'val' initializer should be a constant value
e: file:///C:/Users/pc-name/AppData/Local/Pub/Cache/git/background_location-55c7845ce11b72975ab529d2b2fdf1c982fa01a8/android/src/main/kotlin/com/almoullim/background_location/BackgroundLocationService.kt:27:44 Unresolved reference: BackgroundLocationPlugin
e: file:///C:/Users/pc-name/AppData/Local/Pub/Cache/git/background_location-55c7845ce11b72975ab529d2b2fdf1c982fa01a8/android/src/main/kotlin/com/almoullim/background_location/BackgroundLocationService.kt:96:17 Unresolved reference: Utils
e: file:///C:/Users/pc-name/AppData/Local/Pub/Cache/git/background_location-55c7845ce11b72975ab529d2b2fdf1c982fa01a8/android/src/main/kotlin/com/almoullim/background_location/BackgroundLocationService.kt:207:19 Unresolved reference: BackgroundLocationPlugin
e: file:///C:/Users/pc-name/AppData/Local/Pub/Cache/git/background_location-55c7845ce11b72975ab529d2b2fdf1c982fa01a8/android/src/main/kotlin/com/almoullim/background_location/BackgroundLocationService.kt:211:19 Unresolved reference: BackgroundLocationPlugin
e: file:///C:/Users/pc-name/AppData/Local/Pub/Cache/git/background_location-55c7845ce11b72975ab529d2b2fdf1c982fa01a8/android/src/main/kotlin/com/almoullim/background_location/BackgroundLocationService.kt:241:15 Unresolved reference: BackgroundLocationPlugin
e: file:///C:/Users/pc-name/AppData/Local/Pub/Cache/git/background_location-55c7845ce11b72975ab529d2b2fdf1c982fa01a8/android/src/main/kotlin/com/almoullim/background_location/BackgroundLocationService.kt:244:51 Unresolved reference: BackgroundLocationPlugin
e: file:///C:/Users/pc-name/AppData/Local/Pub/Cache/git/background_location-55c7845ce11b72975ab529d2b2fdf1c982fa01a8/android/src/main/kotlin/com/almoullim/background_location/LocationUpdatesService.kt:168:9 Unresolved reference: Utils
e: file:///C:/Users/pc-name/AppData/Local/Pub/Cache/git/background_location-55c7845ce11b72975ab529d2b2fdf1c982fa01a8/android/src/main/kotlin/com/almoullim/background_location/LocationUpdatesService.kt:177:13 Unresolved reference: Utils
e: file:///C:/Users/pc-name/AppData/Local/Pub/Cache/git/background_location-55c7845ce11b72975ab529d2b2fdf1c982fa01a8/android/src/main/kotlin/com/almoullim/background_location/LocationUpdatesService.kt:252:13 Unresolved reference: Utils
e: file:///C:/Users/pc-name/AppData/Local/Pub/Cache/git/background_location-55c7845ce11b72975ab529d2b2fdf1c982fa01a8/android/src/main/kotlin/com/almoullim/background_location/LocationUpdatesService.kt:255:13 Unresolved reference: Utils

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':background_location:compileDebugKotlin'.
> A failure occurred while executing org.jetbrains.kotlin.compilerRunner.GradleCompilerRunnerWithWorkers$GradleKotlinCompilerWorkAction
   > Compilation error. See log for more details

I was able to fix this by running flutter clean:

flutter clean
flutter pub get
flutter run

@thicorrea1
Copy link

same here

@abr13
Copy link

abr13 commented Jun 29, 2024

I made a fork here:

https://github.com/lukaskurz/background_location/tree/master

This fork contains fixes for both the issues mentioned by @LukasP94 as well as the issues found in the other fork described by @sisalik1 .

I tested it on emulator with API 34 as well as API 29/30 on device, so it should work with both before/after API 33 changes.

None of the solutions work for me!
Manifest:

<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION" />
    <uses-permission android:name="android.permission.ACCESS_FINE_LOCATION" />
    <uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
    <uses-permission android:name="android.permission.ACCESS_BACKGROUND_LOCATION"/>

App crashes:
java.lang.RuntimeException: Unable to create service com.almoullim.background_location.LocationUpdatesService: java.lang.SecurityException: Starting FGS with type location callerApp=ProcessRecord{2e22cea 7459:com.techilex.oilcom.oilcom/u0a680} targetSDK=34 requires permissions: all of the permissions allOf=true [android.permission.FOREGROUND_SERVICE_LOCATION] any of the permissions allOf=false [android.permission.ACCESS_COARSE_LOCATION, android.permission.ACCESS_FINE_LOCATION] and the app must be in the eligible state/exemptions to access the foreground only permission

@Bassam-Reis
Copy link

None of the previous solutions work for me :(
note: all required permissions are allowed.

Error text:
Caused by: java.lang.SecurityException: com.rose_holding.rose_app: One of RECEIVER_EXPORTED or RECEIVER_NOT_EXPORTED should be specified when a receiver isn't being registered exclusively for system broadcasts

@erighet
Copy link

erighet commented Jul 9, 2024

I made a fork here:
https://github.com/lukaskurz/background_location/tree/master
This fork contains fixes for both the issues mentioned by @LukasP94 as well as the issues found in the other fork described by @sisalik1 .
I tested it on emulator with API 34 as well as API 29/30 on device, so it should work with both before/after API 33 changes.

@lukaskurz I tried using your fork on my Samsung A52s (API 34), but it did not compile,

e: file:///C:/Users/pc-name/AppData/Local/Pub/Cache/git/background_location-55c7845ce11b72975ab529d2b2fdf1c982fa01a8/android/src/main/kotlin/com/almoullim/background_location/BackgroundLocationService.kt:27:41 Const 'val' initializer should be a constant value
e: file:///C:/Users/pc-name/AppData/Local/Pub/Cache/git/background_location-55c7845ce11b72975ab529d2b2fdf1c982fa01a8/android/src/main/kotlin/com/almoullim/background_location/BackgroundLocationService.kt:27:44 Unresolved reference: BackgroundLocationPlugin
e: file:///C:/Users/pc-name/AppData/Local/Pub/Cache/git/background_location-55c7845ce11b72975ab529d2b2fdf1c982fa01a8/android/src/main/kotlin/com/almoullim/background_location/BackgroundLocationService.kt:96:17 Unresolved reference: Utils
e: file:///C:/Users/pc-name/AppData/Local/Pub/Cache/git/background_location-55c7845ce11b72975ab529d2b2fdf1c982fa01a8/android/src/main/kotlin/com/almoullim/background_location/BackgroundLocationService.kt:207:19 Unresolved reference: BackgroundLocationPlugin
e: file:///C:/Users/pc-name/AppData/Local/Pub/Cache/git/background_location-55c7845ce11b72975ab529d2b2fdf1c982fa01a8/android/src/main/kotlin/com/almoullim/background_location/BackgroundLocationService.kt:211:19 Unresolved reference: BackgroundLocationPlugin
e: file:///C:/Users/pc-name/AppData/Local/Pub/Cache/git/background_location-55c7845ce11b72975ab529d2b2fdf1c982fa01a8/android/src/main/kotlin/com/almoullim/background_location/BackgroundLocationService.kt:241:15 Unresolved reference: BackgroundLocationPlugin
e: file:///C:/Users/pc-name/AppData/Local/Pub/Cache/git/background_location-55c7845ce11b72975ab529d2b2fdf1c982fa01a8/android/src/main/kotlin/com/almoullim/background_location/BackgroundLocationService.kt:244:51 Unresolved reference: BackgroundLocationPlugin
e: file:///C:/Users/pc-name/AppData/Local/Pub/Cache/git/background_location-55c7845ce11b72975ab529d2b2fdf1c982fa01a8/android/src/main/kotlin/com/almoullim/background_location/LocationUpdatesService.kt:168:9 Unresolved reference: Utils
e: file:///C:/Users/pc-name/AppData/Local/Pub/Cache/git/background_location-55c7845ce11b72975ab529d2b2fdf1c982fa01a8/android/src/main/kotlin/com/almoullim/background_location/LocationUpdatesService.kt:177:13 Unresolved reference: Utils
e: file:///C:/Users/pc-name/AppData/Local/Pub/Cache/git/background_location-55c7845ce11b72975ab529d2b2fdf1c982fa01a8/android/src/main/kotlin/com/almoullim/background_location/LocationUpdatesService.kt:252:13 Unresolved reference: Utils
e: file:///C:/Users/pc-name/AppData/Local/Pub/Cache/git/background_location-55c7845ce11b72975ab529d2b2fdf1c982fa01a8/android/src/main/kotlin/com/almoullim/background_location/LocationUpdatesService.kt:255:13 Unresolved reference: Utils

FAILURE: Build failed with an exception.

* What went wrong:
Execution failed for task ':background_location:compileDebugKotlin'.
> A failure occurred while executing org.jetbrains.kotlin.compilerRunner.GradleCompilerRunnerWithWorkers$GradleKotlinCompilerWorkAction
   > Compilation error. See log for more details

I was able to fix this by running flutter clean:

flutter clean
flutter pub get
flutter run

i can confirm that using the forked repo from @lukaskurz now the app works fine, i hope these fixes will be merged into official plugin repo

@nzackoya
Copy link

How this issue still hangs here, there are solution suggestions and so many developers needs this. Do you still maintain this package @Almoullim ?

@nzackoya
Copy link

@BWMuller can you please check this issue?

@BWMuller
Copy link
Contributor

@nzackoya Sure. I'll have a look

@nzackoya
Copy link

@BWMuller thanks man

@darkrevenger
Copy link

darkrevenger commented Jul 10, 2024

Hey guys, any news on the fix?

@BWMuller
Copy link
Contributor

@nzackoya @darkrevenger Currently the main issue with this repo being updated is the lack of independent verification of PRs. I know that this SDK34 issue is fixed in #208 as I haven't experienced it myself in my own prod deployed application.

I haven't managed to get a UI test to work where it successfully grants the permissions required and does a mock location event as the independent test. If anyone here has experience in that please give it a try so that we can have a easier update cycles.

Alternatively have a look at the PR, test it on your side and add a comment there if you found any issues. That way "independent" would just change to multiple external people vouching instead which should make it easier for @MoralCode to verify

@nzackoya
Copy link

@BWMuller seems the fix has been merged already, I just noticed, it is on master branch already, but not released to pub.dev. Tried the lates code from the master branch, the issue is fixed, works fine so far, not sure if it need some more tests. I guess it just needs a release to pub.dev

@Hamza-Ayed
Copy link

add these permission





use this fork

background_location:
    git:
      url: https://github.com/dharmik-dalwadi-seaflux/background_location.git
      ref: master

then it will work and make sure to use like this class

class LocationBackgroundController extends GetxController {
  @override
  void onInit() {
    super.onInit();
    requestLocationPermission();
  }

  Future<void> requestLocationPermission() async {
    var status = await Permission.locationAlways.status;
    if (!status.isGranted) {
      status = await Permission.locationAlways.request();
    }

    if (status.isGranted) {
      configureBackgroundLocation();
    } else {
      // Handle permission denial
      print("Location permission denied");
    }
  }

  Future<void> configureBackgroundLocation() async {
    await BackgroundLocation.setAndroidNotification(
      title: "Background Location",
      message: "Tracking location...",
      icon: "@mipmap/ic_launcher",
    );

    // Set the location update interval to 5 seconds
    BackgroundLocation.setAndroidConfiguration(5000);
    BackgroundLocation.startLocationService();

    BackgroundLocation.getLocationUpdates((location) {
      // Handle location updates here
      print("Latitude: ${location.latitude}, Longitude: ${location.longitude}");
    });

    startBackLocation();
  }

  void startBackLocation() async {
    Timer.periodic(const Duration(seconds: 5), (timer) async {
      await getBackgroundLocation();
    });
  }

  Future<void> getBackgroundLocation() async {
    var status = await Permission.locationAlways.status;
    if (status.isGranted) {
      // The location service is already started in configureBackgroundLocation
      // No need to call startLocationService again
      BackgroundLocation.getLocationUpdates((location) {
        // Handle location updates here
        print(
            "Latitude: ${location.latitude}, Longitude: ${location.longitude}");
      });
    } else {
      // Request permission if not granted
      await Permission.locationAlways.request();
    }
  }
}

@MoralCode
Copy link
Collaborator

MoralCode commented Jul 25, 2024

@BWMuller seems the fix has been merged already, I just noticed, it is on master branch already, but not released to pub.dev. Tried the lates code from the master branch, the issue is fixed, works fine so far, not sure if it need some more tests. I guess it just needs a release to pub.dev

Unfortunately i dont have access to pub.dev. If the fix for this is already on main i can make a "pending release" tag to make the status clearer. Ill go do that

@KarinBerg
Copy link

Some hint for publishing a new version for a existing app with the above changes via Google Play Store:

I have a automated build pipeline which pblish my app into the internal test track in Google Play Store.

After consuming the master branch of "background_location" in my app and try to publish this in Playstore, I got the error: "You must let us know whether your app uses any Foreground Service permissions.".

The only way I found to solve this, is to manually upload the aab file to the track. Only then I got a new policy declaration entry in "App content" section where I have to explain why my app needs the foreground service.

Screenshot 2024-08-02 at 11 57 53

@xunreal75
Copy link

It's not related to the issue above.

You can find a notification service called in foreground in LocationUpdateService.kt

Therefore you must add ForgroundService declaration.
[https://developer.android.com/develop/background-work/services/foreground-services]

@yasngencc
Copy link

Hi,

I am still experiencing issues with the background_location package on Android 13 with target SDK 34. Despite following all the recommended steps, including adding the necessary permissions like FOREGROUND_SERVICE_LOCATION in the manifest, my app crashes with the error:
`
java.lang.SecurityException: Starting FGS with type location callerApp=ProcessRecord{...} requires permissions: all of the permissions allOf=true [android.permission.FOREGROUND_SERVICE_LOCATION] any of the permissions allOf=false [android.permission.ACCESS_COARSE_LOCATION, android.permission.ACCESS_FINE_LOCATION] and the app must be in the eligible state/exemptions to access the foreground only permission.

`
It seems that even after granting all permissions, the app does not pass the validation for the foreground service type location. I have tried various solutions, including updating the tools:replace in the manifest, but none have resolved the issue.

Is there a specific configuration or workaround needed for Android 13 or SDK 34 that I might be missing? Any guidance on how to proceed would be greatly appreciated.

Thank you!

@mrLorick
Copy link

mrLorick commented Sep 6, 2024

Caused by: java.lang.SecurityException: Starting FGS with type location callerApp=ProcessRecord{c980963 4073:com.dulb.solid_waste_management/u0a436} targetSDK=34 requires permissions: all of the permissions allOf=true [android.permission.FOREGROUND_SERVICE_LOCATION] any of the permissions allOf=false [android.permission.ACCESS_COARSE_LOCATION, android.permission.ACCESS_FINE_LOCATION] and the app must be in the eligible state/exemptions to access the foreground only permission

background_location:
git:
url: https://github.com/dharmik-dalwadi-seaflux/background_location.git
ref: master

Please help guys- its urgent

@mrLorick
Copy link

mrLorick commented Sep 6, 2024

<uses-permission android:name="android.permission.FOREGROUND_SERVICE_LOCATION" />

@mrLorick
Copy link

mrLorick commented Sep 6, 2024

USE THIS PERMISSION uses-permission android:name="android.permission.FOREGROUND_SERVICE_LOCATION"

Hi,

I am still experiencing issues with the background_location package on Android 13 with target SDK 34. Despite following all the recommended steps, including adding the necessary permissions like FOREGROUND_SERVICE_LOCATION in the manifest, my app crashes with the error: ` java.lang.SecurityException: Starting FGS with type location callerApp=ProcessRecord{...} requires permissions: all of the permissions allOf=true [android.permission.FOREGROUND_SERVICE_LOCATION] any of the permissions allOf=false [android.permission.ACCESS_COARSE_LOCATION, android.permission.ACCESS_FINE_LOCATION] and the app must be in the eligible state/exemptions to access the foreground only permission.

` It seems that even after granting all permissions, the app does not pass the validation for the foreground service type location. I have tried various solutions, including updating the tools:replace in the manifest, but none have resolved the issue.

Is there a specific configuration or workaround needed for Android 13 or SDK 34 that I might be missing? Any guidance on how to proceed would be greatly appreciated.

Thank you!
uses-permission android:name="android.permission.FOREGROUND_SERVICE_LOCATION"

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests