question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

With Android device, once select "take photos" or "choose from library", App will crash ~!

See original GitHub issue

But on Genymotion simulator, everything is OK.

I captured the certain error, it seems there is conflict with react-native-navigation, but I don’t know which file I can modify to fix this issue.

error log:

FATAL EXCEPTION: mqt_native_modules
Process: com.aotumeeting, PID: 16467
java.lang.UnsupportedOperationException: NavigationActivity must implement OnImagePickerPermissionsCallback
at com.imagepicker.ImagePickerModule.permissionsCheck(ImagePickerModule.java:594)
at com.imagepicker.ImagePickerModule.launchCamera(ImagePickerModule.java:225)
at com.imagepicker.ImagePickerModule.launchCamera(ImagePickerModule.java:203)
at com.imagepicker.ImagePickerModule$2.onTakePhoto(ImagePickerModule.java:159)
at com.imagepicker.utils.UI$1.onClick(UI.java:54)

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:8 (3 by maintainers)

github_iconTop GitHub Comments

6reactions
aarontrankcommented, May 17, 2017

You either need to have NavigationActivity implement OnImagePickerPermissionsCallback or you need to modify ImagePickerModule to cast the activity to a PermissionAwareActivity instead of an OnImagePickerPermissionsCallback.

See PermissionAwareActivity line 576-597, Here’s the change I made:

else
{
  String[] PERMISSIONS = {Manifest.permission.WRITE_EXTERNAL_STORAGE, Manifest.permission.CAMERA};
  if (activity instanceof ReactActivity)
  {
    ((ReactActivity) activity).requestPermissions(PERMISSIONS, requestCode, listener);
  }
  else if (activity instanceof PermissionAwareActivity)
  {
    ((PermissionAwareActivity) activity).requestPermissions(PERMISSIONS, requestCode, listener);
  }
  else
  {
    final String errorDescription = new StringBuilder(activity.getClass().getSimpleName())
      .append(" must implement ")
      .append(PermissionAwareActivity.class.getSimpleName())
      .toString();
    throw new UnsupportedOperationException(errorDescription);
  }
  return false;
}
1reaction
mfekimcommented, Mar 6, 2018

Hi @aarontrank,

Thank you for your solution! I think we can just replace ReactActivity by PermissionAwareActivity since ReactActivity implements PermissionAwareActivity.

Current code

...
String[] PERMISSIONS = {Manifest.permission.WRITE_EXTERNAL_STORAGE, Manifest.permission.CAMERA};
if (activity instanceof ReactActivity)
{
  ((ReactActivity) activity).requestPermissions(PERMISSIONS, requestCode, listener);
}
else if (activity instanceof OnImagePickerPermissionsCallback)
{
  ((OnImagePickerPermissionsCallback) activity).setPermissionListener(listener);
  ActivityCompat.requestPermissions(activity, PERMISSIONS, requestCode);
}
else
{
  final String errorDescription = new StringBuilder(activity.getClass().getSimpleName())
          .append(" must implement ")
          .append(OnImagePickerPermissionsCallback.class.getSimpleName())
          .toString();
  throw new UnsupportedOperationException(errorDescription);
}
return false;
...

New solution

...
String[] PERMISSIONS = {Manifest.permission.WRITE_EXTERNAL_STORAGE, Manifest.permission.CAMERA};
if (activity instanceof PermissionAwareActivity)
{
  ((PermissionAwareActivity) activity).requestPermissions(PERMISSIONS, requestCode, listener);
}
else if (activity instanceof OnImagePickerPermissionsCallback)
{
  ((OnImagePickerPermissionsCallback) activity).setPermissionListener(listener);
  ActivityCompat.requestPermissions(activity, PERMISSIONS, requestCode);
}
else
{
  final String errorDescription = new StringBuilder(activity.getClass().getSimpleName())
          .append(" must implement ")
          .append(OnImagePickerPermissionsCallback.class.getSimpleName())
          .toString();
  throw new UnsupportedOperationException(errorDescription);
}
return false;
...
Read more comments on GitHub >

github_iconTop Results From Across the Web

App crashes when selecting photo from PhotoLibrary in ...
I was trying to select a photo from the photo library using a Android device , the app crashed. I have followed the...
Read more >
Xamarin Android app crashing right after taking (or selecting ...
Occasionally and intermittently, the app will crash after taking a photo with the camera OR selecting an image from the phone's gallery.
Read more >
image_picker crash after taking 2 or 3 pictures on ... - GitHub
Run the image_picker example app; Select image picker camera; Repeat until the app crashes (I have crashes after 3-4 photos).
Read more >
Detect and diagnose crashes - Android Developers
An app that is written using Java or Kotlin crashes if it throws an unhandled exception, represented by the Throwable class.
Read more >
ionic android : when choose image from gallery the app crash
It will be easier and you will get more control in accessing images and its properties. You can use either Camera plugin or...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found