简体   繁体   中英

App crashes picking image from external storage

My onActivityResult code

@Override
protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
    super.onActivityResult(requestCode, resultCode, data);

    if (requestCode == GalleryPick && resultCode == RESULT_OK && data!= null) {
        Uri imageUri = data.getData();

        CropImage.activity()
                .setGuidelines(CropImageView.Guidelines.ON)
                .setAspectRatio(1,1)
                .start(SettingsActivity.this);
    }

    if (requestCode == CropImage.CROP_IMAGE_ACTIVITY_REQUEST_CODE) {
        CropImage.ActivityResult result = CropImage.getActivityResult(data);
        if (resultCode == RESULT_OK) {
            Uri resultUri = result.getUri();
        } else if (resultCode == CropImage.CROP_IMAGE_ACTIVITY_RESULT_ERROR_CODE) {
            Exception error = result.getError();
        }
    }
}

when I try to pick image from device gallery it crashes at Image crop activity tell me what is the issue with my code

And the error says

java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=1, result=-1, data=Intent { dat=content://com.google.android.apps.photos.contentprovider/-1/1/content://media/external/images/media/25/ORIGINAL/NONE/1270245750 flg=0x1 clip={text/uri-list U:content://com.google.android.apps.photos.contentprovider/-1/1/content%3A%2F%2Fmedia%2Fexternal%2Fimages%2Fmedia%2F25/ORIGINAL/NONE/1270245750} }} to activity {com.gihan.mechat/com.gihan.mechat.SettingsActivity}: android.content.ActivityNotFoundException: Unable to find explicit activity class {com.gihan.mechat/com.theartofdev.edmodo.cropper.CropImageActivity}; have you declared this activity in your AndroidManifest.xml?

And app crash exactly at

start(SettingsActivity.this);

`

The error tells you why it's happening have you declared this activity in your AndroidManifest.xml? Have you?

Check for permission, I had this type of issue once, For API > 29 we need this code below in the in the manifest file.

android: requestLegacyExternalStorage = true

This code is necessary for getting storage permission. Also, go to permission manager in setting in your phone and check the toggle button there.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM