Android Image Deposit System Album update Display instance detailed

Source: Internet
Author: User

Android Image Deposit System Album update Display instance detailed

In the process of developing Android, we could not avoid the possibility of making a custom album or creating a local folder to store the images we need. Take a photo album, for example, we create a test folder, after a photo is stored in the specified test folder, and then displayed in the album, like the effect. Can be displayed immediately after the shot. However, in the actual development process after we save a picture and not immediately update the display of this image, we need to restart the phone to be displayed in the System album.

Here's a way to insert a system gallery:

MediaStore.Images.Media.insertImage (Getcontentresolver (), Mbitmap, "", "" ");
This method allows you to insert a picture into the system gallery. However, after inserting it does not appear immediately and requires sending a broadcast: Sendbroadcast (New Intent (intent.action_media_mounted, Uri.parse ("file://" + Environment.getexternalstoragedirectory ())));
To notify the system to scan the entire SD card, if the more things in the SD will scan the longer, and the scan we can not access the SD card, so the implementation of this way is not friendly to the user.

Here we can use the system Api:mediascannerconnection to our method for scanning updates:

    1. @Override
    2. protected void onCreate (Bundle savedinstancestate) {
    3. super.o Ncreate (savedinstancestate);
    4. mhandler.sendemptymessagedelayed (1, +);
    5. mconnection =new mediascannerconnection (mcontext,this);
    6. }
    7. @Override
    8. public void onmediascannerconnected () {
    9. mconnection.scanfile ("/s Dcard/image.jpg "," image/jpeg ");
    10. }
    11. @Override
    12. public void onscancompleted (String s, Uri Uri) {
    13. log.v ("Huan", "s Can completed ");
    14. Mconnection.disconnect ();
    15. }

http://www.kmjdad.com/
http://www.jnsjzyy.com/
http://www.czhkwl.com/
http://www.express-o2o.com/
http://www.gzjindao.com/
http://www.chumingchuanmeiyishu.com/
http://www.thcxb.com/
http://www.xingguangkeji.com/
http://www.gdrhsy.com/
http://www.clhuiji.com/
http://www.nxjianye.com/
http://www.tjmingsheng.com/
http://www.gangguan022.com/
http://www.zyjbp.com/
http://www.qianhangmy.com/
http://www.tzminbell.com/

Copy Code

But this method I found in the process of the problem is: the incoming context will be mediascannerconnection has been held, resulting in oom. So you need to be aware of the activity when you use it.

We can also broadcast by specifying a path so that you can avoid scanning the entire SD card:

    1. Sendbroadcast (New Intent (intent.action_media_mounted, Uri.parse ("file://" + Environment.getexternalstoragedirectory () + Picpath));
Copy Code

Photo Update tips and precautions to share to everyone, hope to help you.

Android Image Deposit System Album update Display instance detailed

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.