1

I'm really new to react-native and android app building, and I'm facing with this problem. I can't solve this for almost a week so I hope I can get some solution here..

Once this.refs.cam.capture(options, cb) on android, capture method return nothing on android. Everything works fine on ios.

Similar issue is this #138

I can not get any response from CameraManager.capture(options); in react-native-camera/index.js.

This is my whole code related react-native-camera.

CameraView.js

componentWillMount() {
    navigator.geolocation.getCurrentPosition(
        (position) => {
            this.setState({ location: { latitude: position.coords.latitude, longitude: position.coords.longitude} });
        },
        error => console.log(error),
        { enableHighAccuracy: true, timeout: 7000, maximumAge: 1000 }
    )
}

startRecording() {
    const options = { location: this.state.location };

    // this is called
    //    console.log("level 1");

    // capture function is defined
    // console.log(this.camera.capture);

    this.camera.capture({ metadata: options })
        .then((data) => {
            const asset = { isStatic: true };
            if (Platform.OS === 'ios') {
                if (this.props.camera.mode === Camera.constants.CaptureMode.still) {
                    asset.uri = `data:image/jpeg;base64,${data.data}`;
                    asset.path = data.path;
                } else {
                    asset.uri = data.path.replace('file://', '');
                    asset.path = data.path.replace('file://', '');
                }
            } else if (Platform.OS === 'android') {
                if (this.props.camera.mode === Camera.constants.CaptureMode.still) {
                    // Android has no path
                    asset.uri = `data:image/jpeg;base64,${data.data}`;
                } else {
                    // TODO after capturing android
                    asset.uri = data.path.replace('file://', '');
                    asset.path = data.path.replace('file://', '');
                }
            }

            this.props.mediaSelected(asset);
            this.props.updateLatLng(this.state.location);
            if (this.props.camera.mode === Camera.constants.CaptureMode.still) {
                Image.getSize(
                    asset.uri,
                    (width, height) => {
                        this.props.updateAsset({ width, height });
                    }
                );
            }

            RouteActions.EditView();
        })
        .catch((err) => {
            // TODO error handling
            console.log(err);
        });

    this.props.startRecording();
    if (this.props.camera.mode === Camera.constants.CaptureMode.video && this.state.videoMode === 'short') {
        this.timer = setInterval(this.countTimer, 1000);
    }
}

render() {
    const isCamera = this.props.camera.mode === Camera.constants.CaptureMode.still;
    const recording = this.props.camera.isRecording;

    return (
        <View style={styles.cameraContainer}>
            <Camera
                ref={(cam) => { this.camera = cam; }}
                style={styles.preview}
                type={this.props.camera.type}
                captureMode={this.props.camera.mode}
                captureTarget={isCamera ? Camera.constants.CaptureTarget.memory : Camera.constants.CaptureTarget.disk}
                captureQuality="1080p"
                captureAudio={true}
                playSoundOnCapture={true}
                metadata={'location'}
            />

            <View>
                <TouchableOpacity onPress={this.startRecording}>
                    <Image source={require('./path.png')} resizeMode={'contain'} />
                </TouchableOpacity>

            </View>
        </View>

    );

./noed_modules/react-native-camera/index.js

capture(options) {
    const props = convertNativeProps(this.props);
    options = {
        audio: props.captureAudio,
        barCodeTypes: props.barCodeTypes,
        mode: props.captureMode,
        playSoundOnCapture: props.playSoundOnCapture,
        target: props.captureTarget,
        quality: props.captureQuality,
        type: props.type,
        title: '',
        description: '',
        mirrorImage: props.mirrorImage,
        ...options
    };

    // this is called 
    // console.log("check number 1");

    if (options.mode === Camera.constants.CaptureMode.video) {
        options.totalSeconds = (options.totalSeconds > -1 ? options.totalSeconds : -1);
        options.preferredTimeScale = options.preferredTimeScale || 30;
        this.setState({ isRecording: true });
    }

    // this is also called
    // console.log("check number 6");

    // THIS DOES NOT RETURN ANYTHING
    return CameraManager.capture(options);
}

And this is what logcat say when I run from android studio

07-04 15:08:09.053: I/WindowManager(93): createSurface Window{416b4db8 comp.com/comp.com.receipt paused=false}: DRAW NOW PENDING
07-04 15:08:09.133: D/dalvikvm(146): GC_FOR_ALLOC freed 339K, 36% free 10622K/16455K, paused 164ms
07-04 15:08:09.842: W/WindowManager(93): Window freeze timeout expired.
07-04 15:08:09.842: W/WindowManager(93): Force clearing orientation change: Window{416b4db8 comp.com/comp.com.receipt paused=false}
07-04 15:08:09.922: W/NetworkManagementSocketTagger(93): setKernelCountSet(10006, 0) failed with errno -2
07-04 15:08:09.922: I/ActivityManager(93): No longer want com.android.deskclock (pid 358): hidden #16
07-04 15:08:11.153: D/dalvikvm(146): GC_FOR_ALLOC freed 371K, 36% free 10612K/16455K, paused 68ms
07-04 15:08:11.363: I/Process(772): Sending signal. PID: 772 SIG: 9
07-04 15:08:11.403: V/EmulatedCamera_CallbackNotifier(37): disableMessage: msg_type = 0xffff
07-04 15:08:11.403: V/EmulatedCamera_CallbackNotifier(37):         CAMERA_MSG_ERROR
07-04 15:08:11.403: V/EmulatedCamera_CallbackNotifier(37):         CAMERA_MSG_SHUTTER
07-04 15:08:11.403: V/EmulatedCamera_CallbackNotifier(37):         CAMERA_MSG_FOCUS
07-04 15:08:11.403: V/EmulatedCamera_CallbackNotifier(37):         CAMERA_MSG_ZOOM
07-04 15:08:11.403: V/EmulatedCamera_CallbackNotifier(37):         CAMERA_MSG_PREVIEW_FRAME
07-04 15:08:11.403: V/EmulatedCamera_CallbackNotifier(37):         CAMERA_MSG_VIDEO_FRAME
07-04 15:08:11.403: V/EmulatedCamera_CallbackNotifier(37):         CAMERA_MSG_POSTVIEW_FRAME
07-04 15:08:11.403: V/EmulatedCamera_CallbackNotifier(37):         CAMERA_MSG_RAW_IMAGE
07-04 15:08:11.403: V/EmulatedCamera_CallbackNotifier(37):         CAMERA_MSG_COMPRESSED_IMAGE
07-04 15:08:11.403: V/EmulatedCamera_CallbackNotifier(37):         CAMERA_MSG_RAW_IMAGE_NOTIFY
07-04 15:08:11.403: V/EmulatedCamera_CallbackNotifier(37):         CAMERA_MSG_PREVIEW_METADATA
07-04 15:08:11.403: V/EmulatedCamera_CallbackNotifier(37): **** Currently enabled messages:
07-04 15:08:11.403: V/EmulatedCamera_Camera(37): doStopPreview
07-04 15:08:11.403: V/EmulatedCamera_Camera(37): cancelPicture
07-04 15:08:11.403: V/EmulatedCamera_Camera(37): releaseCamera
07-04 15:08:11.403: V/EmulatedCamera_Camera(37): doStopPreview
07-04 15:08:11.403: V/EmulatedCamera_FakeDevice(37): disconnectDevice
07-04 15:08:11.403: I/CameraService(37): Destroying camera 1
07-04 15:08:11.403: V/EmulatedCamera_Camera(37): closeCamera
07-04 15:08:11.403: V/EmulatedCamera_Camera(37): doStopPreview

Environment

  • node version: 7.2.0
  • react native version: 0.43.3
  • Android 6.0, Android 7.0
  • Emulator Nexus6, Nexus5 and Actual device Sony SO-01
  • react-native-camera Version: 0.7.0

Thanks for reading!!

Ashwini Chougale
  • 1,093
  • 10
  • 26
Kan Uchida
  • 23
  • 1
  • 5

0 Answers0