解决思路如下:
1.在继承ActivityFragment的Activity中调用onActivityResult
@Override
protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (resultCode != RESULT_OK) {
return;
}
//ImageUtil.onActivityResult是自己封装的,你们可用自己封装好的调用系统相机和相册的工具类
ImageUtil.onActivityResult(this, requestCode, resultCode, data, 1000, 1000, () -> {
Bitmap bit = BitmapUtil.getImage(ImageUtil.getFileName());
String imageUrl = BitmapUtil.save(AppConfig.DIR_CPIMG + File.separator + System.currentTimeMillis() + ".png", bit, 1024);
MyLogUtil.e("图片", "imageUrl:" + imageUrl);
EventBus.getDefault().post(new ImageUrlEvent(imageUrl));
});
}
2.在onActivityResult中使用EventBus.getDefault().post(new ImageUrlEvent(imageUrl))存储图片
ImageUrlEvent为自定义class文件

3.最后在所在的Fragment中调用 ,uploadFile是接口

注意:在使用Evenbus是记得注册和,解除注册
Evenbus详细请看:https://www.jianshu.com/p/f9ae5691e1bb
本文介绍了一个在Android应用中实现图片选择及上传的过程。该过程包括从相册或相机选择图片、处理图片并使用EventBus传递图片路径,最后通过接口完成图片上传。

2347

被折叠的 条评论
为什么被折叠?



