gpt4 book ai didi

android - onActivityResult 不调用并且 Fragment 从图像选择器 Android 中自行关闭

转载 作者:太空宇宙 更新时间:2023-11-03 11:10:57 24 4
gpt4 key购买 nike

嗨,我知道有很多与此相关的问题,但我仍然找不到正确的方法:(

我阅读了这个链接 onActivityResult is not being called in Fragment但我找不到解决方案。

              Intent intent = new Intent();
intent.setType("image/*");
intent.setAction(Intent.ACTION_GET_CONTENT);
startActivityForResult(Intent.createChooser(intent, ""),
PICK_IMAGE);


public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (resultCode != Activity.RESULT_CANCELED) {
if (requestCode == PICK_IMAGE && data.getData() != null) {
imagePath = getAbsolutePath(data.getData());

imageLoader.loadImage("file://" + imagePath,
new ImageLoadingListener() {

@Override
public void onLoadingStarted(String imageUri,
View view) {

}

@Override
public void onLoadingFailed(String imageUri,
View view, FailReason failReason) {

}

@Override
public void onLoadingComplete(String imageUri,
View view, Bitmap loadedImage) {
height = loadedImage.getHeight();
width = loadedImage.getWidth();
if (Utils
.validateImageSize(height, width,
getActivity(),
"Image size must be in 480 (width) & 800 (height) with PNG or JPG format"))
imageLoader.displayImage("file://"
+ imagePath, ivSubmitImgWord,
options);
}

@Override
public void onLoadingCancelled(String imageUri,
View view) {
}
});

}
}

}

当我从图库中选择图片时,有时不会调用 onActivityResult 并且 Fragment 已关闭。请任何人帮助我解决这个问题。

最佳答案

您需要删除 fragment 中的 super.onActivityResult(requestCode, resultCode, data); 并覆盖

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {}

关于android - onActivityResult 不调用并且 Fragment 从图像选择器 Android 中自行关闭,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25138038/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com