Raja0sama / rn-foreground-service

Foreground Service for React Native made with ❤
https://rn-foreground.vercel.app/
148 stars 70 forks source link

Android 14 #78

Open Muddasir390 opened 12 months ago

Muddasir390 commented 12 months ago

it's not working on android 14

nilaybrahmbhatt commented 9 months ago

it's not working on android 14, any solution till now?

Pauligrinder commented 8 months ago

This is the reason why it doesn't work on Android 14: https://developer.android.com/about/versions/14/changes/fgs-types-required

By adding the necessary configuration, I managed to get it to start on my Android 14 phone. This is what I changed.

The third part is the only thing that actually changed in the library, and that should be somehow updated so it will get the service type from the app... And please note that these changes are to get backround location. For other stuff, different definitions are needed.

Perry1207 commented 8 months ago

ServiceInfo.FOREGROUND_SERVICE_TYPE_LOCATION was not working for me. I found out that the value of this constant is 8. So you can also use just 8 as third parameter

startForeground(id, notification, 8);

Perry1207 commented 8 months ago

Refrence for above comment: https://developer.android.com/reference/android/content/pm/ServiceInfo#FOREGROUND_SERVICE_TYPE_LOCATION

Pauligrinder commented 8 months ago

ServiceInfo.FOREGROUND_SERVICE_TYPE_LOCATION was not working for me. I found out that the value of this constant is 8. So you can also use just 8 as third parameter

startForeground(id, notification, 8);

The constant should work but you need to import android.content.pm.ServiceInfo; :) Directly passing the number will of course do the trick as well since it's just a constant defined to make the code more readable.

Upendra672 commented 7 months ago

I tried with a constant value 8 and import android.content.pm.ServiceInfo; in android 14 but still not working any solution?

suman379 commented 5 months ago

@Pauligrinder you saved our day. Thank you.

keerthanaMol commented 5 months ago

@suman379 @Pauligrinder where should add update code please explain detail.i stuck with this issue around couple of weeks

Pauligrinder commented 5 months ago

where should add update code please explain detail.i stuck with this issue around couple of weeks

For the library code, you can edit it directly in node_modules/@supersami/rn-foreground-service/android/src/main/java/com/supersami/foregroundservice/ForegroundService.java, but it will of course be overwritten if you reinstall. The safest way I guess is to fork the whole library, make the change, and then install your own fork from github (or just make a patch with the change, but I'm not familiar with doing that myself)

On a sidenote, if it has taken you several weeks to figure it out even with the help provided here, I think you really should go back to studying RN and Android programming... I mean, it only took me 1-2 hours to figure this out without any help other than the Google-documentation, so it's really not rocket science if you know anything about what you're doing. Sorry for the passive aggressive tone, but it just annoys me very deeply when people don't seem to put any effort into what they're doing.

suman379 commented 5 months ago

you can use patch-package package to patch after modification

wilmxre commented 4 months ago

ServiceInfo.FOREGROUND_SERVICE_TYPE_LOCATION was not working for me. I found out that the value of this constant is 8. So you can also use just 8 as third parameter

startForeground(id, notification, 8);

can confirm, on a samsung tablet with android 14 i had this line added, but it didn't work at all:

startForeground(id, notification, ServiceInfo.FOREGROUND_SERVICE_TYPE_LOCATION);

then i replaced ServiceInfo.FOREGROUND_SERVICE_TYPE_LOCATION with 8 and after that it worked

josegoval commented 4 months ago

This solution is not working for me. Do I need something extra besides this?

Domesan-U commented 4 months ago

This solution is not working for me. Do I need something extra besides this?

Did you find out the solution?

josegoval commented 4 months ago

This solution is not working for me. Do I need something extra besides this?

Did you find out the solution?

No I didn't 😞

ivanoikon commented 2 months ago

When will servicetype parameter be added to start method? It is necessary