React-native-image-crop-picker: No response on @android

Created on 26 Oct 2016  Â·  19Comments  Â·  Source: ivpusic/react-native-image-crop-picker

Version

Tell us which versions you are using:

  • react-native-image-crop-picker v0.10.1
  • react-native v0.3.5

Platform

Tell us to which platform this issue is related

  • Android

Expected behaviour

Return image object

Actual behaviour

Returns nothing, promise is not fullfilled

Steps to reproduce

  1. Call ImagePicker.openCamera().then((image) => console.log(image));
  2. Camera opens up
  3. After accepting the photo, the camera closes, but no response is returned

    Attachments

react-native-image-crop-picker.txt

All 19 comments

can you try to debug this? I cannot reproduce it

on android 7/nexus 6P when you try to call camera, nothing happens

file:///storage/emulated/0/Pictures/image-c1fcccb4-e260-4f68-a7d4-e6b425a10e7a.jpg exposed beyond app through ClipData.Item.getUri()
    at createErrorFromErrorData (http://localhost:8081/index.android.bundle?platform=android&dev=true&hot=false&minify=false:7367:11)
    at http://localhost:8081/index.android.bundle?platform=android&dev=true&hot=false&minify=false:7330:35
    at MessageQueue.__invokeCallback (http://localhost:8081/index.android.bundle?platform=android&dev=true&hot=false&minify=false:7710:10)
    at http://localhost:8081/index.android.bundle?platform=android&dev=true&hot=false&minify=false:7562:8
    at guard (http://localhost:8081/index.android.bundle?platform=android&dev=true&hot=false&minify=false:7481:1)
    at MessageQueue.invokeCallbackAndReturnFlushedQueue (http://localhost:8081/index.android.bundle?platform=android&dev=true&hot=false&minify=false:7561:1)
    at message (file:///Applications/React%20Native%20Debugger.app/Contents/Resources/app.asar/js/debugger.worker.js:97:57)

Hey, i fixed my problem. I forgot to call super inside my overwritten onActivityResult method.

    @Override
    public void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data); <-- this line was missing
        MainApplication.getCallbackManager().onActivityResult(requestCode, resultCode, data);
    }

@vitalyrotari your issue is described here http://stackoverflow.com/questions/38200282/android-os-fileuriexposedexception-file-storage-emulated-0-test-txt-exposed. Do you have a time to submit PR for this issue?

@ivpusic thanks for help, camera works fine, below describes all changes

AndroidManifest.xml

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    ...
    <application
        ...
        <provider
            android:name="android.support.v4.content.FileProvider"
            android:authorities="${applicationId}.provider"
            android:exported="false"
            android:grantUriPermissions="true">
            <meta-data
                android:name="android.support.FILE_PROVIDER_PATHS"
                android:resource="@xml/provider_paths"/>
        </provider>
    </application>
</manifest>

android/app/src/main/res/xml/provider_paths.xml

<?xml version="1.0" encoding="utf-8"?>
<paths xmlns:android="http://schemas.android.com/apk/res/android">
  <external-path name="external_files" path="."/>
</paths>

com/reactnative/ivpusic/imagepicker/PickerModule.java

private void initiateCamera(Activity activity) {

        try {

            int requestCode = CAMERA_PICKER_REQUEST;
            Intent cameraIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
            tmpImage = true;
            // we create a tmp file to save the result
            File imageFile = createNewFile(true);

//            mCameraCaptureURI = Uri.fromFile(imageFile);

            mCameraCaptureURI = FileProvider.getUriForFile(activity,
                    activity.getApplicationContext().getPackageName() + ".provider",
                    imageFile);

            cameraIntent.putExtra(MediaStore.EXTRA_OUTPUT, mCameraCaptureURI);
            if (cameraIntent.resolveActivity(mReactContext.getPackageManager()) == null) {
                mPickerPromise.reject(E_CANNOT_LAUNCH_CAMERA, "Cannot launch camera");
                return;
            }

            activity.startActivityForResult(cameraIntent, requestCode);
        } catch (Exception e) {
            mPickerPromise.reject(E_FAILED_TO_OPEN_CAMERA, e);
        }

    }

but, when I press on accept photo, will take this error:

'_data' does not exist
    at createErrorFromErrorData (http://localhost:8081/index.android.bundle?platform=android&dev=true&hot=false&minify=false:7367:11)
    at http://localhost:8081/index.android.bundle?platform=android&dev=true&hot=false&minify=false:7330:35
    at MessageQueue.__invokeCallback (http://localhost:8081/index.android.bundle?platform=android&dev=true&hot=false&minify=false:7710:10)
    at http://localhost:8081/index.android.bundle?platform=android&dev=true&hot=false&minify=false:7562:8
    at guard (http://localhost:8081/index.android.bundle?platform=android&dev=true&hot=false&minify=false:7481:1)
    at MessageQueue.invokeCallbackAndReturnFlushedQueue (http://localhost:8081/index.android.bundle?platform=android&dev=true&hot=false&minify=false:7561:1)
    at message (file:///Applications/React%20Native%20Debugger.app/Contents/Resources/app.asar/js/debugger.worker.js:97:57)

My issue is solved.

issue solved, you can see modified PickerModule.java

@vitalyrotari did you maybe tried new PickerModule file with older Android versions? Does it still work?

@ivpusic I'll add some fixes for SDK 19, seems to work fine, will add final version a bit later ;)

I have the same issue.(ಥ_ಥ)

@ivpusic PickerModule Rev.4, tested and works on next SDK's:

  • [x] 19 (4.4)
  • [x] 21 (5.0)
  • [x] 22 (5.1)
  • [x] 23 (6.0)
  • [x] 24 (7.0)

I have the same problem. sdkVersion 23, buildtoolsVersion 23.0.1
@vitalyrotari After I've changed PickerModule.java to your version (PickerModule Rev.4)
and reinstalled on my device I'm now getting: "E_FAILED_TO_OPEN_CAMERA" :-(

@dudukenesto try to request permission before you call camera and look at this instructions

import { PermissionsAndroid } from 'react-native';

const granted = await PermissionsAndroid.requestPermission(
  PermissionsAndroid.PERMISSIONS.CAMERA, {
    title: 'Camera Access',
    message: 'Your message here...'
  }
);

if (granted) {
  try {
    const result = await ImagePicker
      .openCamera({
        width: 640,
        height: 480,
        cropping: false
      });
  } catch (e) {
    // ... 
  }
}

Simply updating the package to the latest version fixed this for me.

@vitalyrotari I stand corrected.. your solution does fix the problem for "openCamera" function. Now it's working properly (yeaahh!) , BUT... with your code changes a new problem is created when using "openPicker" function. I get this error "E_NO_IMAGE_DATA_FOUND". With the original code this feature is working properly. So I guess I need to choose which feature is more important...
BTW, do you know of a component for choosing a file of any type from local storage? (not only images)

@dudukenesto yeah, sorry my bad :) I'll update, now must work fine camera and image picker

Rev.5

@vitalyrotari now everything is working. Thanks!

@vitalyrotari could you please try https://github.com/ivpusic/react-native-image-crop-picker/releases/tag/v0.10.2. I did small refactoring on top of your gist. Could you please try it on your devices to see if still everything works for you as well?
Thanks

@ivpusic all is working fine ;)

Was this page helpful?
0 / 5 - 0 ratings