Android image download to local, System gallery does not display

Source: Internet
Author: User

Maybe we all know when we download the image to the Android phone, and then call the system library to open the picture, prompting "cannot find the specified item".

That's because the images we've inserted haven't been updated, so just plug the pictures into the system gallery and then the clockwork broadcast will be OK.

/**     * Picture inserted into the system album, solve the system library cannot open picture problem     *    /public static void Insertimagetosystemgallery (context context, String FilePath, Bitmap Bitmap) {        MediaStore.Images.Media.insertImage (Context.getcontentresolver (), Bitmap, "", "");        Intent Intent = new Intent (intent.action_media_scanner_scan_file);        Uri uri = uri.fromfile (new File (FilePath));        Intent.setdata (URI);        Context.sendbroadcast (intent);    }

Attach the method to get the picture path:

Gets the absolute path of the picture private  String getfilepathbycontentresolver (context context, Uri Uri) {if (null = = URI) {return null;}        Cursor C = context.getcontentresolver (). Query (URI, NULL, NULL, NULL, or null);        String FilePath  = null;        if (null = = c) {            throw new IllegalArgumentException (                    "Query on" + URI + "returns null result.")        ;        try {            if (c.getcount ()! = 1) | |!c.movetofirst ()) {            } else {            FilePath = c.getstring (            c.getcolumnindex Orthrow (Mediacolumns.data));            }        } finally {            c.close ();        }        return filePath;    }

  

Android image download to local, System gallery does not display

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.