List of usage examples for android.os Environment DIRECTORY_PICTURES
String DIRECTORY_PICTURES
To view the source code for android.os Environment DIRECTORY_PICTURES.
Click Source Link
From source file:Utils.GenericUtils.java
public static String readFileFromAppDir(Context context, String fileName) { if (!bFilePath) { dirFile = context.getExternalFilesDir(Environment.DIRECTORY_PICTURES); bFilePath = true;/*from ww w. j a v a2 s . c o m*/ } if (dirFile != null) { try { File downloadDir = new File(dirFile, fileName); fileName = downloadDir.getCanonicalPath(); } catch (Exception e) { Log.e("readFile", e.getMessage()); fileName = null; } } return fileName; }
From source file:hochschuledarmstadt.photostream_tools.ImageCacher.java
private File concatImageFilePath(Context context, String imageFileName) { File file = new File(context.getFilesDir(), imageFileName); if (!file.exists() && isExternalStorageAccessible()) { File pictureDirectory = context.getExternalFilesDir(Environment.DIRECTORY_PICTURES); if (!pictureDirectory.exists()) pictureDirectory.mkdir();// www . j a va 2 s . c o m file = new File(pictureDirectory, imageFileName); } return file; }
From source file:com.foreignreader.WordListActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); if (BooksActivity.TESTING_STORGE) ObjectsFactory.storageFile = new File(getFilesDir(), "words.db"); else {//w w w . ja v a 2s . c o m File file = new File( Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES).getParentFile(), "Foreign Reader"); file.mkdirs(); ObjectsFactory.storageFile = new File(file, "words.db"); } setContentView(R.layout.activity_word_list); if (BooksActivity.TESTING_STORGE) ObjectsFactory.storageFile = new File(getFilesDir(), "words.db"); else { File file = new File( Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES).getParentFile(), "Foreign Reader"); file.mkdirs(); ObjectsFactory.storageFile = new File(file, "words.db"); } int[] n = ObjectsFactory.getDefaultDatabase().getWordsCount(); if (findViewById(R.id.word_detail_container) != null) { // The detail container view will be present only in the // large-screen layouts (res/values-large and // res/values-sw600dp). If this view is present, then the // activity should be in two-pane mode. mTwoPane = true; TextView stat = (TextView) findViewById(R.id.statisticTextView); stat.setText("Known words: " + n[0] + " Unknown words: " + n[1]); // In two-pane mode, list items should be given the // 'activated' state when touched. ((WordListFragment) getSupportFragmentManager().findFragmentById(R.id.word_list)) .setActivateOnItemClick(true); } }
From source file:org.disrupted.rumble.util.FileUtil.java
public static File getReadableAlbumStorageDir() throws IOException { if (!isExternalStorageReadable()) throw new IOException("Storage is not readable"); File file = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES), RUMBLE_IMAGE_ALBUM_NAME);// w w w . j a v a 2 s . c o m if (!file.mkdirs()) { } return file; }
From source file:org.apache.cordova.plugin.AMImageDownloader.java
private void savePhoto(Bitmap bmp) { OutputStream fOut = null;//w w w.j a v a2 s . co m Calendar c = Calendar.getInstance(); String date = String.valueOf((c.get(Calendar.MONTH))) + String.valueOf((c.get(Calendar.DAY_OF_MONTH))) + String.valueOf((c.get(Calendar.YEAR))) + String.valueOf((c.get(Calendar.HOUR_OF_DAY))) + String.valueOf((c.get(Calendar.MINUTE))) + String.valueOf((c.get(Calendar.SECOND))); File file = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES), date.toString() + ".png"); try { fOut = new FileOutputStream(file); bmp.compress(Bitmap.CompressFormat.PNG, 85, fOut); fOut.flush(); fOut.close(); /**Update image to gallery**/ Intent mediaScanIntent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE); Uri contentUri = Uri.fromFile(file); mediaScanIntent.setData(contentUri); this.cordova.getActivity().sendBroadcast(mediaScanIntent); } catch (Exception e) { e.printStackTrace(); } }
From source file:com.synconset.ImageFetcher.java
public ImageFetcher(Context ct) { context = ct;//from w w w . j av a 2 s . c o m executor = Executors.newCachedThreadPool(); dir_thumb = new File(context.getExternalFilesDir(Environment.DIRECTORY_PICTURES), "thumb"); if (!dir_thumb.isDirectory() && !dir_thumb.mkdir()) { // failed } try { FileUtils.cleanDirectory(dir_thumb); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } }
From source file:util.Utils.java
public static String getPictureStorageDirectory() { return Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES) + "/" + Constant.CACHE_DIR;/* w w w . j av a2 s.co m*/ }
From source file:com.pixby.texo.images.ImageUtil.java
private static String getAppStoragePath(String albumName) { File storageDir = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES), albumName);// w ww . ja va2s. c om if (!storageDir.exists()) { if (!storageDir.mkdirs()) { Log.e(TAG, "getAppStoragePath mkdirs failed: " + storageDir.getAbsolutePath()); } } return storageDir.getPath(); }
From source file:org.fashiontec.bodyapps.sync.SyncPic.java
/** * Gets path to save the images downloaded from API. * @param type//from w w w.jav a 2s . c o m * @param id * @param picID * @return */ private File getOutputMediaFile(PicTypes type, String id, String picID) { String IMAGE_DIRECTORY_NAME = "BodyApp" + File.separator + id; File mediaStorageDir = new File( Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES), IMAGE_DIRECTORY_NAME); // Create the storage directory if it does not exist if (!mediaStorageDir.exists()) { if (!mediaStorageDir.mkdirs()) { Log.d(IMAGE_DIRECTORY_NAME, "Oops! Failed create " + IMAGE_DIRECTORY_NAME + " directory"); return null; } } File mediaFile; String name = null; switch (type) { case FRONT: name = "front.jpg"; break; case SIDE: name = "side.jpg"; break; case BACK: name = "back.jpg"; break; case OTHER: name = picID + ".jpg"; break; } mediaFile = new File(mediaStorageDir.getPath() + File.separator + name); return mediaFile; }
From source file:ch.uzh.supersede.feedbacklibrary.utils.Utils.java
@NonNull private static String captureScreenshot(final Activity activity) { // Create the 'Screenshots' folder if it does not already exist File screenshotDir = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES), SCREENSHOTS_DIR_NAME);//from ww w .j av a2 s . c o m screenshotDir.mkdirs(); // Image name 'Screenshot_YearMonthDay-HourMinuteSecondMillisecond.png' Calendar calendar = Calendar.getInstance(); calendar.setTimeInMillis(System.currentTimeMillis()); String imageName = "Screenshot_" + calendar.get(Calendar.YEAR) + (calendar.get(Calendar.MONTH) + 1) + calendar.get(Calendar.DAY_OF_MONTH); imageName += "-" + calendar.get(Calendar.HOUR_OF_DAY) + calendar.get(Calendar.MINUTE) + calendar.get(Calendar.SECOND) + calendar.get(Calendar.MILLISECOND) + ".png"; File screenshotFile = new File(screenshotDir, imageName); // Create the screenshot file try { if (screenshotFile.exists()) { screenshotFile.delete(); } screenshotFile.createNewFile(); } catch (IOException e) { Log.e(TAG, "Failed to create a new file", e); } // Capture the current screen View rootView = activity.getWindow().getDecorView().getRootView(); rootView.setDrawingCacheEnabled(true); Bitmap imageBitmap = Bitmap.createBitmap(rootView.getDrawingCache()); rootView.setDrawingCacheEnabled(false); FileOutputStream fos; try { fos = new FileOutputStream(screenshotFile); imageBitmap.compress(Bitmap.CompressFormat.PNG, 100, fos); fos.flush(); fos.close(); } catch (Exception e) { Log.e(TAG, "Failed to write the bitmap to the file", e); } // Add the screenshot image to the Media Provider's database Intent mediaScanIntent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE); Uri contentUri = Uri.fromFile(screenshotFile); mediaScanIntent.setData(contentUri); activity.sendBroadcast(mediaScanIntent); return screenshotFile.getAbsolutePath(); }