当应用程序进入前台时,是否有可能阻止'react-native-camera‘卸载?
我已经使用'@voximplant/react-native- foreground - service‘成功创建了一个前台服务,但似乎当应用程序失去焦点时,'react-native-camera’正在卸载。
我知道这是正常的行为,但我在寻找一种方法,用应用程序在前台扫描条形码,并对这些事件做出反应。
发布于 2019-08-28 17:33:06
该问题是由“react-native-camera”实现引起的。此模块处理应用程序状态更改。如果应用程序转到后台,它会停止摄像头本身。一旦应用程序被带到前台,它就会恢复摄像头:
@Override
public void onHostResume() {
if (hasCameraPermissions()) {
if ((mIsPaused && !isCameraOpened()) || mIsNew) {
mIsPaused = false;
mIsNew = false;
start();
}
} else {
RNCameraViewHelper.emitMountErrorEvent(this, "Camera permissions not granted - component could not be rendered.");
}
}
@Override
public void onHostPause() {
if (mIsRecording) {
mIsRecordingInterrupted = true;
}
if (!mIsPaused && isCameraOpened()) {
mIsPaused = true;
stop();
}
}@voximplant/react- native - foreground service模块只启动前台服务,不会影响其他模块,也不会调用任何android原生摄像头接口。前台服务旨在解决Android9 (P) (https://developer.android.com/about/versions/pie/android-9.0-changes-all#bg-sensor-access)中引入的隐私限制。
https://stackoverflow.com/questions/57593397
复制相似问题