Android saves images locally and can be displayed in albums

Source: Internet
Author: User

App is more and more humanized: The interface is beautiful, service diversification, operation is very convenient. For example, when we use the app, we find that there is a comparison of the pictures to save to the phone, just click on the app to provide the Save button on it. So how does this picture be saved to the local implementation?

Saving the picture is simple, as follows:

/** Default File Save path First */
private static final String save_pic_path=environment.getexternalstoragestate (). Equalsignorecase (Environment.media _mounted)? Environment.getexternalstoragedirectory (). GetAbsolutePath (): "/mnt/sdcard";//Save to SD card
private static final String Save_real_path = save_pic_path+ "/good/savepic";//exact location of the Save

Here is the method of saving, passing in the parameters can be:

public static void SaveFile (Bitmap BM, string fileName, String path) throws IOException {
String Subforder = Save_real_path + PATH;
File Foder = new file (Subforder);
if (!foder.exists ()) {
Foder.mkdirs ();
}
File Mycapturefile = new file (Subforder, fileName);
if (!mycapturefile.exists ()) {
Mycapturefile.createnewfile ();
}
Bufferedoutputstream BOS = new Bufferedoutputstream (new FileOutputStream (Mycapturefile));
Bm.compress (Bitmap.CompressFormat.JPEG, N, BOS);
Bos.flush ();
Bos.close ();
}

This is preserved, but sometimes obviously saved, why do you not see it when you enter the album? Anyway, I encountered such a problem, the original we in the preservation of success, but also to send a system broadcast notification phone has a picture update, broadcast as follows:

Intent Intent = new Intent (intent.action_media_scanner_scan_file);
Uri uri = uri.fromfile (file);
Intent.setdata (URI);
Context.sendbroadcast (intent);//The purpose of this broadcast is to update the library, send this broadcast into the album will be able to find your saved pictures! , remember to upload your updated file oh

Android saves images locally and can be displayed in albums

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.