Is there any way to run a foreground service in react native?

情到浓时终转凉″ 提交于 2020-05-13 07:31:02

问题


I've been doing a few searches on google trying to find a way to run foreground services in react native but I haven't found much about it.

Is anyone aware of how to accomplish this? This is what I mean by foreground service: https://developer.android.com/guide/components/services.html#Foreground


回答1:


I have an example React Native Foreground Service app here. In this example, I'm doing a Bluetooth scan every 10 seconds and attempting to run a Foreground Service so that the scans will continue even if the app isn't in the foreground.

You can remove the call in index.js that does the BLE scan and you'll have a simple RN Foreground Service example.




回答2:


Here's a package react-native-foreground-service i found, while I was dealing with the same issue.



来源:https://stackoverflow.com/questions/46228999/is-there-any-way-to-run-a-foreground-service-in-react-native

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!