ivpusic / react-native-image-crop-picker

iOS/Android image picker with support for camera, video, configurable compression, multiple images and cropping
MIT License
6.08k stars 1.55k forks source link

cannot be cast to com.facebook.react.modules.core.PermissionAwareActivity #362

Open shutupzk opened 7 years ago

shutupzk commented 7 years ago

Version

Tell us which versions you are using:

Platform

Tell us to which platform this issue is related

Attachments

can not run ...

// stacktrace or any other useful debug info java.lang.ClassCastException: com.founder.doctor_app.MainActivity cannot be cast to com.facebook.react.modules.core.PermissionAwareActivity at com.reactnative.ivpusic.imagepicker.PickerModule.permissionsCheck(PickerModule.java:221) at com.reactnative.ivpusic.imagepicker.PickerModule.openPicker(PickerModule.java:349) at java.lang.reflect.Method.invoke(Native Method) at com.facebook.react.bridge.BaseJavaModule$JavaMethod.invoke(BaseJavaModule.java:368) at com.facebook.react.cxxbridge.JavaModuleWrapper.invoke(JavaModuleWrapper.java:138) at com.facebook.react.bridge.queue.NativeRunnable.run(Native Method) at android.os.Handler.handleCallback(Handler.java:761) at android.os.Handler.dispatchMessage(Handler.java:98) at com.facebook.react.bridge.queue.MessageQueueThreadHandler.dispatchMessage(MessageQueueThreadHandler.java:31) at android.os.Looper.loop(Looper.java:156) at com.facebook.react.bridge.queue.MessageQueueThreadImpl$3.run(MessageQueueThreadImpl.java:208) at java.lang.Thread.run(Thread.java:776)

ivpusic commented 7 years ago

are you sure you have react-native v0.44 installed? try running ./gradlew clean

favioConV commented 5 years ago

Hi! I`m having a similar issue that was posted here.

Version

Tell us which versions you are using:

Platform

Tell us to which platform this issue is related

Attachments

In my case, the error shown is this: << -- E/unknown:ReactNative: Exception in native call java.lang.ClassCastException: host.exp.exponent.MainActivity cannot be cast to com.facebook.react.modules.core.PermissionAwareActivity at com.reactnative.ivpusic.imagepicker.PickerModule.permissionsCheck(PickerModule.java:233) at com.reactnative.ivpusic.imagepicker.PickerModule.openPicker(PickerModule.java:375) at java.lang.reflect.Method.invoke(Native Method) at com.facebook.react.bridge.JavaMethodWrapper.invoke(JavaMethodWrapper.java:374) at com.facebook.react.bridge.JavaModuleWrapper.invoke(JavaModuleWrapper.java:162) at com.facebook.react.bridge.queue.NativeRunnable.run(Native Method) at android.os.Handler.handleCallback(Handler.java:739) at android.os.Handler.dispatchMessage(Handler.java:95) at com.facebook.react.bridge.queue.MessageQueueThreadHandler.dispatchMessage(MessageQueueThreadHandler.java:31) at android.os.Looper.loop(Looper.java:158) at com.facebook.react.bridge.queue.MessageQueueThreadImpl$3.run(MessageQueueThreadImpl.java:194) at java.lang.Thread.run(Thread.java:818)

-- >>

If you need further info, please ask for it without hesitate.

Thanks in advance :)

apzuk3 commented 5 years ago

@favioConV did you fix the problem?

favioConV commented 5 years ago

Hi @apzuk3! Sadly i haven't fixed yet. Sorry for the late response. Hope you can find it.

karvulf commented 4 years ago

I got the same problem when integrating the react native app to an existing android app. The react-native-image-picker has the option to implement OnImagePickerPermissionsCallback to solve that problem.

Unfortunately this part is missing in react-native-image-crop-picker. It would be nice if that problem could get a fix.

Gopalakrishnan-V commented 4 years ago

How did you solve this issue? @karvulf

phatmann commented 4 years ago

I found a very simple solution. To whatever Activity you are launching image picker from, add this code:

import com.facebook.react.modules.core.PermissionAwareActivity;
import com.facebook.react.modules.core.PermissionListener;

....

public class MyActivity extends Activity implements PermissionAwareActivity {
    private PermissionListener permissionListener;

   ....

       @TargetApi(Build.VERSION_CODES.M)
    public void requestPermissions(String[] permissions, int requestCode, PermissionListener listener) {
        permissionListener = listener;
        requestPermissions(permissions, requestCode);
    }

    public void onRequestPermissionsResult(int requestCode, String[] permissions, int[] grantResults) {
        if (permissionListener != null && permissionListener.onRequestPermissionsResult(requestCode, permissions, grantResults)) {
            permissionListener = null;
        }
    }
}

I got the code from here. Suggested here.