![](/img/trans.png)
[英]Image only Shared with Whatsapp but not with other apps in Android
[英]Android: problems reading shared image by other apps
我正在开发一个使用与其他应用程序(例如画廊,浏览器)共享的图像的应用程序。
编码:
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();
}
}
}
当我第一次从浏览器共享图像时,它可以正常工作。 片段开始,可以将图像加载到ImageView。 但是第二次使用浏览器的共享选项,它没有加载新图像。 (仅当我手动清除应用程序数据时。)
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);
}
您知道我如何获得较新的图像吗?
从您发布的代码来看,问题与您的Glide
通话有关。 由于其缓存, Glide
不会将新请求加载到ImageView
。
为了解决这个问题,您可以尝试执行以下操作:
Glide.with(imgOfEntity.getContext())
.load(imgByteArray)
.diskCacheStrategy(DiskCacheStrategy.NONE)
.skipMemoryCache(true)
.into(imgOfEntity);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.