|
Android will save the image to the SD card, the album will not be there to this picture, because there is no update its index, generally you need to boot several times. Of course, we can manually update its index.
1, first save the file to the SD card.
String filePath = "xxx"; // full path
saveImgToSDcard (filePath);
2, increasing the Android internal media index.
public boolean saveImgToGallery (String filePath) {
boolean sdCardExist = Environment.getExternalStorageState (). equals (
android.os.Environment.MEDIA_MOUNTED); // determine whether there sd card
if (! sdCardExist)
return false;
try {
ContentValues values = new ContentValues ();
values.put ( "datetaken", new Date () toString ().);
values.put ( "mime_type", "image / jpg");
values.put ( "_ data", filePath);
Application app = DoctorApplication.getInstance ();
ContentResolver cr = app.getContentResolver ();
cr.insert (MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values);
} Catch (Exception e) {
e.printStackTrace ();
}
return true;
}
3, the refresh filePath upper level directory
MediaScannerConnection.scanFile (MyLanJingCode.this, new String [] {Environment.getExternalStoragePublicDirectory (Environment.DIRECTORY_DCIM) .getPath () + "/" + filePath.getParentFile () getAbsolutePath ().}, Null, null);
This will increase in time to see the pictures in the album. |
|
|
|