英文:
App crashes picking image from external storage
问题
我的onActivityResult代码
@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();
}
}
}
当我尝试从设备图库选择图像时,应用在图像裁剪活动处崩溃
告诉我代码存在什么问题
**错误信息如下**
java.lang.RuntimeException: 在 activity {com.gihan.mechat/com.gihan.mechat.SettingsActivity} 中传递结果 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} }} 失败:android.content.ActivityNotFoundException: 无法找到显式活动类 {com.gihan.mechat/com.theartofdev.edmodo.cropper.CropImageActivity};您是否在 AndroidManifest.xml 中声明了此活动?
**应用程序崩溃正好发生在**
start(SettingsActivity.this);
英文:
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);
`
答案1
得分: 1
检查权限,我曾经遇到过这种问题,
对于 API > 29,我们需要在清单文件的
android:requestLegacyExternalStorage="true"
这段代码是获取存储权限所必需的。
同时,前往手机设置中的权限管理器,检查切换按钮。
英文:
Check for permission, I had this type of issue once,
For API > 29 we need this code below in the <application> </application> 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.
答案2
得分: 0
错误告诉您为什么会发生这种情况:“您是否在您的 AndroidManifest.xml 中声明了此活动?” 您有吗?
英文:
The error tells you why it's happening have you declared this activity in your AndroidManifest.xml?
Have you?
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论