[英]Android: problems reading shared image by other apps
I am developing an app that uses images shared from other apps (eg gallery, browser). 我正在开发一个使用与其他应用程序(例如画廊,浏览器)共享的图像的应用程序。
The code: 编码:
public void handleImage() {
Intent intent = getIntent();
Uri imgUri = (Uri) intent.getParcelableExtra(Intent.EXTRA_STREAM);
if (imgUri != null){
ByteArrayOutputStream stream = new ByteArrayOutputStream();
try {
InputStream imgInputStream = context.getContentResolver().openInputStream(imgUri);
Bitmap img = (BitmapFactory.decodeStream(imgInputStream));
img.compress(Bitmap.CompressFormat.PNG, 100, stream);
byte[] imgByteArray = stream.toByteArray();
Bundle bundle = new Bundle();
bundle.putByteArray("IMAGE_BYTEARRAY", imgByteArray);
FragmentEntityEdit fragmentEntityEdit = new FragmentEntityEdit();
fragmentEntityEdit.setArguments(bundle);
changeFragment(fragmentEntityEdit,true,true);
} catch (FileNotFoundException e) {
e.printStackTrace();
}
}
}
When I share image from browser for the first time, it works fine. 当我第一次从浏览器共享图像时,它可以正常工作。 Fragment is started and image can be loaded to ImageView.
片段开始,可以将图像加载到ImageView。 But for the second time I use share option of the browser, it is not loading the new image.
但是第二次使用浏览器的共享选项,它没有加载新图像。 (Only if I clear application data manually.)
(仅当我手动清除应用程序数据时。)
UPDATE (ImageView image load in fragmentEntityEdit): in OnCreateView: UPDATE(fragmentEntityEdit中的ImageView图像加载):在OnCreateView中:
Bundle bundle = getArguments();
if (bundle != null) {
imgByteArray = bundle.getByteArray("IMAGE_BYTEARRAY");
}
ImageView imgOfEntity = view.findViewById(R.id.imageview_imgofentity);
if (imgByteArray != null) {
imgOfEntity.setImageBitmap(null);
Glide
.with(getActivity())
.load(imgByteArray)
.into(imgOfEntity);
}
Do you know how can I reach newer images? 您知道我如何获得较新的图像吗?
From the code you have posted, the issue is related to your Glide
call. 从您发布的代码来看,问题与您的
Glide
通话有关。 Glide
is not loading the new request into your ImageView
, due to its cache. 由于其缓存,
Glide
不会将新请求加载到ImageView
。
In order to fix it, you can try something like this: 为了解决这个问题,您可以尝试执行以下操作:
Glide.with(imgOfEntity.getContext())
.load(imgByteArray)
.diskCacheStrategy(DiskCacheStrategy.NONE)
.skipMemoryCache(true)
.into(imgOfEntity);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.