voximplant/react-native-foreground-service

Can we use this for do something in foreground?

Surangaup opened this issue · 8 comments

Is this just for show a notification? If the answer is "YES", this title must be changed. Because the title meaning is developer can use this for do something in foreground as foreground service. if answer is "NO" , please explain where the place which developer put their code for run in foreground.

Looking at the code it seems this library only allow us to create a notification channel, service itself is inside the library.
I've also struggled myself into searching where to put my service code ;-)

Same here. Can this do somethign in the foreground?

@thehellmaker @abouquet Did you guys find any better libraries or source to create foreground services?

@thehellmaker @abouquet Did you guys find any better libraries or source to create foreground services?

Nah, I used only vanilla react-native bridge capabilities... And created service from native side manually

Would really love to see a sample code or maybe if you have any good references?

@callmemonky , you need a 2 way communication to achieve that.

javascript -> native to trigger a start service using method channels => https://reactnative.dev/docs/native-modules-android
native -> javascript if you need to update javascript part without having a screen on foreground (e.g. react-native-sqlite as a database ). It's called "headless js" => https://reactnative.dev/docs/headless-js-android

With these both resources you should be able to achieve that.

Regards,

[EDIT] And I forgot, to create foreground service, official Android documentation should be enought : https://developer.android.com/guide/components/foreground-services

Hi, to make it work you need to add the proper config in the AndroidManifest file:
ex:
<service android:name="com.voximplant.foregroundservice.VIForegroundService" android:foregroundServiceType="location" android:exported="false"> </service>
Once i added the "foregroundServiceType" key, i was able to run the code in background. (In my case it's location update and http request)

However i haven't tested it over a long period of time