List of usage examples for android.os Environment getExternalStoragePublicDirectory
public static File getExternalStoragePublicDirectory(String type)
From source file:mgks.os.webview.MainActivity.java
private File create_image() throws IOException { @SuppressLint("SimpleDateFormat") String file_name = new SimpleDateFormat("yyyy_mm_ss").format(new Date()); String new_name = "file_" + file_name + "_"; File sd_directory = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES); return File.createTempFile(new_name, ".jpg", sd_directory); }
From source file:de.syss.MifareClassicTool.Activities.MainMenu.java
/** * Copy the standard key files ({@link Common#STD_KEYS} and * {@link Common#STD_KEYS_EXTENDED}) form assets to {@link Common#KEYS_DIR}. * Key files are simple text files. Any plain text editor will do the trick. * All key and dump data from this App is stored in * getExternalStoragePublicDirectory(Common.HOME_DIR) to remain * there after App uninstallation.//from w w w .java 2 s.c o m * @see Common#KEYS_DIR * @see Common#HOME_DIR * @see Common#copyFile(InputStream, OutputStream) */ private void copyStdKeysFilesIfNecessary() { File std = new File(Environment.getExternalStoragePublicDirectory(Common.HOME_DIR) + "/" + Common.KEYS_DIR, Common.STD_KEYS); File extended = new File( Environment.getExternalStoragePublicDirectory(Common.HOME_DIR) + "/" + Common.KEYS_DIR, Common.STD_KEYS_EXTENDED); AssetManager assetManager = getAssets(); if (!std.exists()) { // Copy std.keys. try { InputStream in = assetManager.open(Common.KEYS_DIR + "/" + Common.STD_KEYS); OutputStream out = new FileOutputStream(std); Common.copyFile(in, out); in.close(); out.flush(); out.close(); } catch (IOException e) { Log.e(LOG_TAG, "Error while copying 'std.keys' from assets " + "to external storage."); } } if (!extended.exists()) { // Copy extended-std.keys. try { InputStream in = assetManager.open(Common.KEYS_DIR + "/" + Common.STD_KEYS_EXTENDED); OutputStream out = new FileOutputStream(extended); Common.copyFile(in, out); in.close(); out.flush(); out.close(); } catch (IOException e) { Log.e(LOG_TAG, "Error while copying 'extended-std.keys' " + "from assets to external storage."); } } }
From source file:net.zjy.zxcardumper.Activities.MainMenu.java
/** * Copy the standard key files ({@link Common#STD_KEYS} and * {@link Common#STD_KEYS_EXTENDED}) form assets to {@link Common#KEYS_DIR}. * Key files are simple text files. Any plain text editor will do the trick. * All key and dump data from this App is stored in * getExternalStoragePublicDirectory(Common.HOME_DIR) to remain * there after App uninstallation./*from ww w .j ava 2 s . c om*/ * @see Common#KEYS_DIR * @see Common#HOME_DIR * @see Common#copyFile(InputStream, OutputStream) */ private void copyStdKeysFilesIfNecessary() { File std = new File(Environment.getExternalStoragePublicDirectory(Common.HOME_DIR) + "/" + Common.KEYS_DIR, Common.STD_KEYS); /*File extended = new File(Environment.getExternalStoragePublicDirectory( Common.HOME_DIR) + "/" + Common.KEYS_DIR, Common.STD_KEYS_EXTENDED);*/ AssetManager assetManager = getAssets(); if (!std.exists()) { // Copy zx.keys. try { InputStream in = assetManager.open("key-files/zx.keys"); OutputStream out = new FileOutputStream(std); Common.copyFile(in, out); in.close(); out.flush(); out.close(); } catch (IOException e) { Log.e(LOG_TAG, "Error while copying 'zx.keys' from assets " + "to external storage."); e.printStackTrace(); } } /*if (!extended.exists()) { // Copy extended-zx.keys. try { InputStream in = assetManager.open( Common.KEYS_DIR + "/" + Common.STD_KEYS_EXTENDED); OutputStream out = new FileOutputStream(extended); Common.copyFile(in, out); in.close(); out.flush(); out.close(); } catch(IOException e) { Log.e(LOG_TAG, "Error while copying 'extended-zx.keys' " + "from assets to external storage."); } }*/ }
From source file:at.ac.tuwien.caa.docscan.ui.CameraActivity.java
/** * Returns the path to the directory in which the images are saved. * * @param appName name of the app, this is used for gathering the directory string. * @return the path where the images are stored. *///from w ww .java2s . c o m public static File getMediaStorageDir(String appName) { File mediaStorageDir = new File( Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES), appName); // Create the storage directory if it does not exist if (!mediaStorageDir.exists()) { if (!mediaStorageDir.mkdirs()) { return null; } } return mediaStorageDir; }
From source file:com.lastsoft.plog.GamesFragment.java
private File createImageFile() throws IOException { // Create an image file name String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date()); String fileName = "PLAY_" + timeStamp + "_"; String imageFileName = fileName; File storageDir = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES); File plogDir = new File(storageDir, "/Plog/"); File image = File.createTempFile(imageFileName, ".jpg", plogDir); // Save a file: path for use with ACTION_VIEW intents mCurrentPhotoPath = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES) + "/Plog/" + image.getName();/*from ww w. j a va 2 s. c o m*/ return image; }
From source file:cn.suishen.email.activity.MessageViewFragmentBase.java
private File performAttachmentSave(MessageViewAttachmentInfo info) { Attachment attachment = Attachment.restoreAttachmentWithId(mContext, info.mId); Uri attachmentUri = AttachmentUtilities.getAttachmentUri(mAccountId, attachment.mId); try {//from w w w. j a v a 2 s.c om File downloads = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS); downloads.mkdirs(); File file = Utility.createUniqueFile(downloads, attachment.mFileName); Uri contentUri = AttachmentUtilities.resolveAttachmentIdToContentUri(mContext.getContentResolver(), attachmentUri); InputStream in = mContext.getContentResolver().openInputStream(contentUri); OutputStream out = new FileOutputStream(file); IOUtils.copy(in, out); out.flush(); out.close(); in.close(); String absolutePath = file.getAbsolutePath(); // Although the download manager can scan media files, scanning only happens after the // user clicks on the item in the Downloads app. So, we run the attachment through // the media scanner ourselves so it gets added to gallery / music immediately. MediaScannerConnection.scanFile(mContext, new String[] { absolutePath }, null, null); DownloadManager dm = (DownloadManager) getActivity().getSystemService(Context.DOWNLOAD_SERVICE); dm.addCompletedDownload(info.mName, info.mName, false /* do not use media scanner */, info.mContentType, absolutePath, info.mSize, true /* show notification */); // Cache the stored file information. info.setSavedPath(absolutePath); // Update our buttons. updateAttachmentButtons(info); return file; } catch (IOException ioe) { // Ignore. Callers will handle it from the return code. } return null; }
From source file:es.upv.riromu.arbre.main.MainActivity.java
/** * CreateImageFile//from w w w .j a v a 2s . c o m */ private File createJSONFile(String JSON) throws IOException { // Create an image file name String timeStamp = String.valueOf(System.currentTimeMillis() / 1000L); String imageFileName = "PLATANUS" + timeStamp; File storageDir = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES); File file = File.createTempFile(imageFileName, /* prefix */ ".txt", /* suffix */ storageDir /* directory */ ); FileWriter filewriter = new FileWriter(file); filewriter.write(JSON); filewriter.flush(); filewriter.close(); // Save a file: path for use with ACTION_VIEW intents return file; }
From source file:es.upv.riromu.arbre.main.MainActivity.java
/** * CreateImageFile//w ww .jav a2 s . c o m */ private File createImageFile() throws IOException { // Create an image file name String timeStamp = String.valueOf(System.currentTimeMillis() / 1000L); String imageFileName = "PLATANUS" + timeStamp; File storageDir = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES); File image = File.createTempFile(imageFileName, /* prefix */ ".jpg", /* suffix */ storageDir /* directory */ ); // Save a file: path for use with ACTION_VIEW intents return image; }
From source file:kr.ac.kpu.wheeling.blackbox.Camera2VideoFragment.java
public File getVideoStorageDir(String albumName) { //File file = new File(Environment.getExternalStorageDirectory(), albumName); File file = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM), albumName); if (canWritable() && !file.isDirectory()) { if (!file.mkdirs()) { Log.e("STORAGE", "Directory not created"); }/*ww w .jav a2 s . c o m*/ } return file; }
From source file:es.upv.riromu.arbre.main.MainActivity.java
private File createImageFile(Bitmap bm) throws IOException { // Create an image file name String timeStamp = String.valueOf(System.currentTimeMillis() / 1000L); String imageFileName = "PLATANUS" + timeStamp; File storageDir = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES); File image = File.createTempFile(imageFileName, /* prefix */ ".jpg", /* suffix */ storageDir /* directory */ );/* w w w. j a va2 s.c om*/ OutputStream os; try { os = new FileOutputStream(image); bm.compress(Bitmap.CompressFormat.JPEG, 100, os); os.flush(); os.close(); } catch (Exception e) { Log.e(TAG, "Error writing bitmap", e); } return image; }