简体   繁体   English

无法在Android中将图片保存到图库

[英]Having trouble saving image to gallery in Android

I'm writing an Android app and I'm trying to save the image to the phone's image gallery. 我正在编写一个Android应用,并且试图将图像保存到手机的图像库中。 When I step through this code it seems to be running fine and no exceptions are thrown. 当我逐步执行此代码时,它似乎运行良好,并且未引发任何异常。 I simply don't see the downloaded images in my gallery and I can't find them on my emulator. 我只是在图库中看不到下载的图像,而在模拟器上也找不到它们。

Why won't the images downloaded with the code below show up in my phone's gallery? 为什么使用下面的代码下载的图像不会显示在手机的图库中?

URL imageURL = new URL(photoRequestUrl);
Bitmap imageBitmap = BitmapFactory.decodeStream(imageURL.openStream());

//getContext().
MediaStore.Images.Media.insertImage(getContext().getContentResolver(), imageBitmap, "title" , "description");

Maybe you reboot your phone will see the picture in the gallery. 也许您重新启动手机会在图库中看到图片。 Try to write this line after writing some into storage. 将一些内容写入存储后,尝试写入此行。

sendBroadcast(new Intent(Intent.ACTION_MEDIA_MOUNTED, Uri.parse("file://" + Environment.getExternalStorageDirectory())));

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM