Android Java - Tutorial - Save Image Into Gallery HD

11.04.2013
JeffMeJones JMJ applications save file = https://www.dropbox.com/s/gvz4v7ra3w7mv4w/Save.java public void SaveImage(Context context,Bitmap ImageToSave) TheThis = context; String file_path = Environment.getExternalStorageDirectory().getAbsolutePath()+ NameOfFolder; String CurrentDateAndTime= getCurrentDateAndTime(); File dir = new File(file_path); if(!dir.exists()) dir.mkdirs(); File file = new File(dir, NameOfFile +CurrentDateAndTime+ ".jpg"); try FileOutputStream fOut = new FileOutputStream(file); ImageToSave.compress(Bitmap.CompressFormat.JPEG, 85, fOut); fOut.flush(); fOut.close(); MakeSureFileWasCreatedThenMakeAvabile(file); AbleToSave(); catch (FileNotFoundException e) UnableToSave(); catch (IOException e)UnableToSave(); private void MakeSureFileWasCreatedThenMakeAvabile(File file) MediaScannerConnection.scanFile(TheThis, new String[] file.toString() , null, new MediaScannerConnection.OnScanCompletedListener() public void onScanCompleted(String path, Uri uri) private String getCurrentDateAndTime() Calendar c = Calendar.getInstance(); SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd-HH-mm-ss"); String formattedDate = df.format(c.getTime()); return formattedDate; private void UnableToSave() Toast.makeText(TheThis, "Picture cannot to gallery", Toast.LENGTH_SHORT).show(); private void AbleToSave() Toast.makeText(TheThis, "Picture saved be saved", Toast.LENGTH_SHORT).show();

Похожие видео