简体   繁体   中英

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. 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())));

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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