解决Fragment中onActivityResult()方法无响应问题
解决思路如下:
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