Java tutorial
//package com.java2s; /* * This is the source code of Telegram for Android v. 1.4.x. * It is licensed under GNU GPL v. 2 or later. * You should have received a copy of the license in this archive (see LICENSE). * * Copyright Nikolai Kudashov, 2013-2014. */ import android.os.Environment; import java.io.File; import java.text.SimpleDateFormat; import java.util.Date; import java.util.Locale; public class Main { public static File generatePicturePath() { try { File storageDir = getAlbumDir(); String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss", Locale.US).format(new Date()); return new File(storageDir, "IMG_" + timeStamp + ".jpg"); } catch (Exception e) { // FileLog.e("tmessages", e); } return null; } private static File getAlbumDir() { File storageDir = null; if (Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState())) { storageDir = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES), "Telegram"); if (!storageDir.mkdirs()) { if (!storageDir.exists()) { // FileLog.d("tmessages", "failed to create directory"); return null; } } } else { // FileLog.d("tmessages", "External storage is not mounted READ/WRITE."); } return storageDir; } }