React-native-image-crop-picker: Nothing happens: openPicker or openCamera

Created on 1 Apr 2020  路  14Comments  路  Source: ivpusic/react-native-image-crop-picker

Version

Tell us which versions you are using:

  • react-native-image-crop-picker v0.28.0
  • react-native v0.62.0

Platform

Tell us to which platform this issue is related

  • Android 9, Samsung S8+

Expected behaviour

Open gallery or camera

Actual behaviour

Nothing happens.

Steps to reproduce

const image = await ImagePicker.openCamera({
  width: 512,
  height: 512,
  cropping: true
});

OR

const image = await ImagePicker.openPicker({
  width: 512,
  height: 512,
  cropping: true
});

Attachments

MyApp.MainActivity                   onUserLeaveHint 
MyApp.MainActivity                   onPause 
ViewRootImpl@c903598[MainActivity]   MSG_WINDOW_FOCUS_CHANGED 0 1 
InputMethodManager                   prepareNavigationBarInfo() DecorView@575667f[MainActivity] 
InputMethodManager                   getNavigationBarColor() -855310 
MainApplication                      getReactNativeHost 
MainApplication                      getReactNativeHost 
ViewRootImpl@c903598[MainActivity]   MSG_WINDOW_FOCUS_CHANGED 1 1 
InputMethodManager                   prepareNavigationBarInfo() DecorView@575667f[MainActivity] 
InputMethodManager                   getNavigationBarColor() -855310 
MainApplication                      getReactNativeHost 
MainApplication                      getReactNativeHost 
MyApp.MainActivity                   onRequestPermissionsResult: 1 
ViewRootImpl@c903598[MainActivity]   setWindowStopped(false) old=false 
MyApp.MainActivity                   onResume 
System.out                           (HTTPLog)-Static: isSBSettingEnabled false 
System.out                           (HTTPLog)-Static: isSBSettingEnabled false 
ViewRootImpl@c903598[MainActivity]   Relayout returned: old=[0,0][1080,2220] new=[0,0][1080,2220] result=0x1 surface={valid=true 479528591360} changed=false 
MyApp.MainActivity$ConnBCastReceiver ConnBCastReceiver.onReceive: android.net.conn.CONNECTIVITY_CHANGE 
System                               A resource failed to call end.  
chatty                               uid=10298(com.myapp) FinalizerDaemon identical 2 lines 
System                               A resource failed to call end.     

Most helpful comment

All 14 comments

Works in iPhone X, but Cancel and Choose after taking a photo are not localized.

Does not work in Google Pixel 2, Android 10 either, so probably something wrong in the Android implementation or permissions. I have my own permissions handling in my app as it uses camera and mic. Maybe the lib cannot handle this and the callback goes to my code when it should go to the lib. This can be seen in the log line onRequestPermissionsResult: 1. If this is the case, it should be fixed in the lib.

I changed my code to use requestPermissions from the ReactActivity not from ActivityCompat and removed the onRequestPermissionsResult (using a callback). Now I'm getting the following error even though the camera permission has already been granted:

Failed to open camera. [Error: Required permission missing]

BTW. Why is WRITE_EXTERNAL_STORAGE always requested? is it really required to have a WRITE access to the external storage to get images from the gallery or camera?

I had to request the WRITE_EXTERNAL_STORAGE permission myself to get it working. Still really don't understand why this is needed for just using the camera and why it needs to be WRITE, not READ?

I suspect it has to do with the compression this library tries to do. It compresses any image you choose, regardless of whether it came from the camera or the file system, and writes it to disk and gives you _its_ URI.

But I only need a base64 version. Don't know if that can be done in memory.

The big question, however is, why do I need to request the permissions and the lib's permission request does not work?

One more problem is that cancelling image selection throws an error. Am I supposed to compare the error description to "User cancelled image selection". I'm sure there could be a better way.

Error: User cancelled image selection]

With Pixel 3, Android 10 I get this even when the user has given both READ and WRITE permissions. This does not happen in Samsung S8 and Android 9.

TransformImageView   onFailure: setImageUri 
TransformImageView   java.io.FileNotFoundException: open failed: EACCES (Permission denied) 
TransformImageView      at android.os.ParcelFileDescriptor.openInternal(ParcelFileDescriptor.java:315)  
TransformImageView      at android.os.ParcelFileDescriptor.open(ParcelFileDescriptor.java:220)  
TransformImageView      at android.content.ContentResolver.openAssetFileDescriptor(ContentResolver.java:1498)   
TransformImageView      at android.content.ContentResolver.openFileDescriptor(ContentResolver.java:1338)    
TransformImageView      at android.content.ContentResolver.openFileDescriptor(ContentResolver.java:1286)    
TransformImageView      at com.yalantis.ucrop.task.BitmapLoadTask.doInBackground(BitmapLoadTask.java:100)   
TransformImageView      at com.yalantis.ucrop.task.BitmapLoadTask.doInBackground(BitmapLoadTask.java:44)    
TransformImageView      at android.os.AsyncTask$3.call(AsyncTask.java:378)  
TransformImageView      at java.util.concurrent.FutureTask.run(FutureTask.java:266) 
TransformImageView      at android.os.AsyncTask$SerialExecutor$1.run(AsyncTask.java:289)    
TransformImageView      at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167)  
TransformImageView      at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641)  
TransformImageView      at java.lang.Thread.run(Thread.java:919)    
image-crop-picker    Promise rejected. Cannot find image data   

Looks like the lib is not compatible with Android 10 and a workaround in the manifest is needed.

https://stackoverflow.com/questions/32524001/java-io-filenotfoundexception-open-failed-eacces-permission-denied

I'm also seeing this issue manifest itself on Android 10.

android:requestLegacyExternalStorage="true"
Adding this to AndroidManifest alleviates the issue, but this workaround will not work with Android 11 in the future.

android:requestLegacyExternalStorage is just a workaround. Unless checking the permissions are fixed, this lib will stop working in the future.

I can confirm that's fixed, I deleted android:requestLegacyExternalStorage and bumped the package version and my AndroidX device is working as expected.

Thanks so much!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

JodiWarren picture JodiWarren  路  3Comments

sergiulucaci picture sergiulucaci  路  3Comments

DISKONEKTeD picture DISKONEKTeD  路  3Comments

leelandclay picture leelandclay  路  3Comments

Martian2Lee picture Martian2Lee  路  3Comments