Simen Russnes
Simen Russnes

Reputation: 2260

'ExponentImagePicker.launchCameraAsync' has been rejected

On a specific device (Samsung Galaxy S9 with Android 9), when I try to open the camera through ExponentImagePicker, I get the following error:

Error: Call to function 'ExponentImagePicker.launchCameraAsync' has been rejected.
Caused by: kotlin.UninitializedPropertyAccessException: lateinit property cameraLauncher has not been initialized

On an Android 9 emulator it works, and also for newer API version emulators. This was working previously, but seems to have stopped working after updating react native and other libraries.

Anything I can do about it?

Code:

import * as ImagePicker from 'expo-image-picker';

const MediaSelector: React.FC<Props> = (props) => {
    const open = async () => {
        const permissions = await ImagePicker.requestCameraPermissionsAsync();
        if (!permissions.granted) return Alert.alert("permission denied!"))
        
        const config: ImagePicker.ImagePickerOptions = {
            mediaTypes: ImagePicker.MediaTypeOptions.Images,
            allowsEditing: true,
            allowsMultipleSelection: false,
            exif: false,
            aspect: [1, 1],
        }
        try {
            const result = await ImagePicker.launchCameraAsync(config);
        } catch (error) {
            console.log(error)
            Alert.alert("error!")
            return
        }
    }
    
    return <Pressable style={styles.container} onPress={open}>
        <ImageView img={props.image}/>
    </Pressable/>
}

versions:

"react": "18.0.0",
"expo-image-picker": "~13.3.1",
"react-native": "0.69.6",

Upvotes: 3

Views: 1516

Answers (4)

nerdBev
nerdBev

Reputation: 1

I also confirm that using Pixel 4 XL with API 32 worked for me. I had been getting this error and using many different devices with API 33:

Error: Call to function 'ExponentImagePicker.launchCameraAsync' has been rejected.
→ Caused by: java.lang.NullPointerException: Parameter specified as non-null is null: method host.exp.exponent.experience.d.checkSelfPermission, parameter permission

Upvotes: 0

Mino
Mino

Reputation: 1

Deleting the device and downgrading to API 32 did the trick for me (Android Studio); API 33 and 34 had this bug; also using a Pixel 4 XL. From what I saw on GitHub Issues, this is an issue that hasn't been figured out yet and is API/Device specific

Upvotes: 0

kuriel
kuriel

Reputation: 1

i commented ensureCameraPermissionsAreGranted() on node_modules/expo-image-picker/android/src/main/java/expo/module/imagepicker/ImagePickerModule.kt

    AsyncFunction("launchCameraAsync") Coroutine { options: ImagePickerOptions ->
          //ensureTargetActivityIsAvailable(options)
          //ensureCameraPermissionsAreGranted()

      val mediaFile = createOutputFile(context.cacheDir, options.mediaTypes.toFileExtension())
      val uri = mediaFile.toContentUri(context)
      val contractOptions = options.toCameraContractOptions(uri)

      launchContract({ cameraLauncher.launch(contractOptions) }, options)
    }

but i check the permission on react-native code manually

and it works like charm, i think there's problem with permission mechanism on kotlin code

Upvotes: 0

craig_tietek
craig_tietek

Reputation: 11

I had the same issue, and for some reason using getCameraPermissionsAsync() fixed the issue - whereas requestCameraPermissionsAsync() on its own would cause launchCameraAsync() to be rejected on Android devices.

See the following:

let permissionResult = await ImagePicker.getCameraPermissionsAsync();
        if(permissionResult.status !== 'granted') {
            permissionResult = await ImagePicker.requestCameraPermissionsAsync();
        }
        if(permissionResult.status !== 'granted') {
            alert("You must turn on camera permissions to record a video.");
        }
        else {
            let result = await ImagePicker.launchCameraAsync({
                mediaTypes: ImagePicker.MediaTypeOptions.Videos,
                allowsEditing: true,
                aspect: [3, 4],
            });

Upvotes: 1

Related Questions