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:sg.fxl.topeka.widget.quiz.ImageQuizView.java
private File createImageFile() throws IOException { int permission = ActivityCompat.checkSelfPermission(getContext(), Manifest.permission.WRITE_EXTERNAL_STORAGE); if (permission == PackageManager.PERMISSION_GRANTED) { // Create an image file name String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date()); String imageFileName = "JPEG_" + timeStamp + "_"; File storageDir = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES); File image = File.createTempFile(imageFileName, ".jpg", storageDir); // Save a file: path for use with ACTION_VIEW intents photoPath = "file://" + image.getPath(); return image; } else {/*from w ww . j a v a 2s . c o m*/ // We don't have permission so prompt the user ActivityCompat.requestPermissions((Activity) getContext(), PERMISSIONS_STORAGE, REQUEST_EXTERNAL_STORAGE); return null; } }
From source file:com.microsoft.projectoxford.visionsample.helper.SelectImageActivity.java
public void takePhoto(View view) { Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); if (intent.resolveActivity(getPackageManager()) != null) { // Save the photo taken to a temporary file. File storageDir = getExternalFilesDir(Environment.DIRECTORY_PICTURES); try {//from w ww .j a va 2 s . co m mFilePhotoTaken = File.createTempFile("IMG_", /* prefix */ ".jpg", /* suffix */ storageDir /* directory */ ); // Create the File where the photo should go // Continue only if the File was successfully created if (mFilePhotoTaken != null) { mUriPhotoTaken = FileProvider.getUriForFile(this, "com.microsoft.projectoxford.visionsample.fileprovider", mFilePhotoTaken); intent.putExtra(MediaStore.EXTRA_OUTPUT, mUriPhotoTaken); // Finally start camera activity startActivityForResult(intent, REQUEST_TAKE_PHOTO); } } catch (IOException e) { setInfo(e.getMessage()); } } }
From source file:com.maxwen.wallpaper.board.fragments.SettingsFragment.java
private void initSettings() { List<Setting> settings = new ArrayList<>(); double cache = (double) FileHelper.getCacheSize(getActivity().getCacheDir()) / FileHelper.MB; NumberFormat formatter = new DecimalFormat("#0.00"); settings.add(new Setting(R.drawable.ic_toolbar_storage, getActivity().getResources().getString(R.string.pref_data_header), "", "", "", Setting.Type.HEADER, -1));//from w w w . ja v a2s. co m settings.add(new Setting(-1, "", getActivity().getResources().getString(R.string.pref_data_cache), getActivity().getResources().getString(R.string.pref_data_cache_desc), String.format(getActivity().getResources().getString(R.string.pref_data_cache_size), formatter.format(cache) + " MB"), Setting.Type.CACHE, -1)); settings.add(new Setting(R.drawable.ic_toolbar_theme, getActivity().getResources().getString(R.string.pref_theme_header), "", "", "", Setting.Type.HEADER, -1)); settings.add(new Setting(-1, "", getActivity().getResources().getString(R.string.pref_theme_dark), getActivity().getResources().getString(R.string.pref_theme_dark_desc), "", Setting.Type.THEME, Preferences.getPreferences(getActivity()).isDarkTheme() ? 1 : 0)); settings.add(new Setting(R.drawable.ic_toolbar_wallpapers, getActivity().getResources().getString(R.string.pref_wallpaper_header), "", "", "", Setting.Type.HEADER, -1)); String directory = ""; if (Preferences.getPreferences(getActivity()).getWallsDirectory() == null) { directory = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES) + "/" + getActivity().getResources().getString(R.string.app_name)).getAbsolutePath(); } else { directory = Preferences.getPreferences(getActivity()).getWallsDirectory() + File.separator; } settings.add(new Setting(-1, "", getActivity().getResources().getString(R.string.pref_wallpaper_location), directory, "", Setting.Type.WALLPAPER, -1)); settings.add(new Setting(-1, "", getActivity().getResources().getString(R.string.wallpaper_scroll_enable), getActivity().getResources().getString(R.string.wallpaper_scroll_enable_desc), "", Setting.Type.SCROLL, Preferences.getPreferences(getActivity()).isScrollWallpaper() ? 1 : 0)); mAdapter = new SettingsAdapter(getActivity(), this, settings); mRecyclerView.setAdapter(mAdapter); }
From source file:com.nichtemna.takeandsavephoto.PhotoFragment.java
/** * Gets list of files in this folder/*from ww w .j a v a 2 s .co m*/ */ private void getFileList() { files.clear(); File root = Environment.getExternalStoragePublicDirectory( Environment.DIRECTORY_PICTURES + "/" + getString(R.string.app_name)); Collections.addAll(files, root.listFiles()); Collections.sort(files, new CustomComparator()); adapter = new ViewPagerAdapter(getActivity(), files); viewPager.setAdapter(adapter); imb_remove.setVisibility(files.size() > 0 ? View.VISIBLE : View.INVISIBLE); }
From source file:arun.com.chameleonskinforkwlp.activities.CameraCapturerActivity.java
/** * Create a temporary file on our storage directory for the camera app to write the photo to. * We also save the location in {@link #takenPhotoPath} so that we can use it after the user * takes the photo./* w w w .j a va 2 s .c o m*/ * * @return The file that was created. * @throws IOException */ private File createTemporaryFile() throws IOException { final String imageFileName = "CAPTURED_IMAGE"; final File storageDir = getExternalFilesDir(Environment.DIRECTORY_PICTURES); final File image = File.createTempFile(imageFileName, /* prefix */ ".jpg", /* suffix */ storageDir /* directory */ ); takenPhotoPath = image.getAbsolutePath(); return image; }
From source file:de.stadtrallye.rallyesoft.model.pictures.PictureManager.java
public PictureManager(Context applicationContext, IDbProvider dbProvider) { context = applicationContext;/*from w w w . j av a2 s .com*/ this.dbProvider = dbProvider; deviceID = Settings.Secure.getString(context.getContentResolver(), Settings.Secure.ANDROID_ID); // To be safe, you should check that the SDCard is mounted // using Environment.getExternalStorageState() before doing this. mediaStorageDir = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES), "rallye"); // This location works best if you want the created images to be shared // between applications and persist after your app has been uninstalled. // Create the storage directory if it does not exist if (!mediaStorageDir.exists()) { if (!mediaStorageDir.mkdirs()) { Log.e(THIS, "failed to create directory"); // throw new UnsupportedOperationException("Failed to create directory"); } } reload(); }
From source file:it.rignanese.leo.slimfacebook.PictureActivity.java
private void DownloadPicture(String url, boolean share) { //check permission if (Build.VERSION.SDK_INT >= 23 && ContextCompat.checkSelfPermission(this, android.Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_DENIED) { //ask permission Toast.makeText(getApplicationContext(), getString(R.string.acceptPermissionAndRetry), Toast.LENGTH_LONG) .show();//from ww w . j a v a2 s. c o m int requestResult = 0; ActivityCompat.requestPermissions(this, new String[] { android.Manifest.permission.WRITE_EXTERNAL_STORAGE }, requestResult); } else { //download photo DownloadManager.Request request = new DownloadManager.Request(Uri.parse(url)); request.setTitle("SlimSocial Download"); // in order for this if to run, you must use the android 3.2 to compile your app if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) { request.allowScanningByMediaScanner(); request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_VISIBLE_NOTIFY_COMPLETED); } String path = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES).getPath(); if (savedPreferences.getBoolean("pref_useSlimSocialSubfolderToDownloadedFiles", false)) { path += "/SlimSocial"; } request.setDestinationInExternalPublicDir(path, "SlimSocial.jpg"); if (share) request.setNotificationVisibility(DownloadManager.Request.VISIBILITY_HIDDEN); // get download service and enqueue file long _idDownloadedFile = downloadManager.enqueue(request); if (share) idDownloadedFile = _idDownloadedFile; else Toast.makeText(getApplicationContext(), getString(R.string.downloadingPhoto), Toast.LENGTH_LONG) .show(); } }
From source file:mil.nga.giat.mage.sdk.utils.MediaUtility.java
public static File createImageFile() throws IOException { // Create an image file name String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date()); String imageFileName = "MAGE_" + timeStamp; File pictures = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES); File directory = new File(pictures, "MAGE"); if (!directory.exists()) { directory.mkdirs();/*from w w w . j a va2 s . co m*/ } return File.createTempFile(imageFileName, /* prefix */ ".jpg", /* suffix */ directory /* directory */ ); }
From source file:org.quantumbadger.redreader.image.ShareImageCallback.java
@Override public void onPermissionGranted() { final RedditAccount anon = RedditAccountManager.getAnon(); LinkHandler.getImageInfo(activity, uri, Constants.Priority.IMAGE_VIEW, 0, new GetImageInfoListener() { @Override/*from w w w . j a v a2 s. c o m*/ public void onFailure(final @CacheRequest.RequestFailureType int type, final Throwable t, final Integer status, final String readableMessage) { final RRError error = General.getGeneralErrorForFailure(activity, type, t, status, uri); General.showResultDialog(activity, error); } @Override public void onSuccess(final ImageInfo info) { CacheManager.getInstance(activity) .makeRequest(new CacheRequest(General.uriFromString(info.urlOriginal), anon, null, Constants.Priority.IMAGE_VIEW, 0, DownloadStrategyIfNotCached.INSTANCE, Constants.FileType.IMAGE, CacheRequest.DOWNLOAD_QUEUE_IMMEDIATE, false, false, activity) { @Override protected void onCallbackException(Throwable t) { BugReportActivity.handleGlobalError(context, t); } @Override protected void onDownloadNecessary() { General.quickToast(context, R.string.download_downloading); } @Override protected void onDownloadStarted() { } @Override protected void onFailure(@CacheRequest.RequestFailureType int type, Throwable t, Integer status, String readableMessage) { final RRError error = General.getGeneralErrorForFailure(context, type, t, status, url.toString()); General.showResultDialog(activity, error); } @Override protected void onProgress(boolean authorizationInProgress, long bytesRead, long totalBytes) { } @Override protected void onSuccess(CacheManager.ReadableCacheFile cacheFile, long timestamp, UUID session, boolean fromCache, String mimetype) { String filename = General.filenameFromString(info.urlOriginal); File dst = new File(Environment.getExternalStoragePublicDirectory( Environment.DIRECTORY_PICTURES), filename); if (dst.exists()) { int count = 0; while (dst.exists()) { count++; dst = new File( Environment.getExternalStoragePublicDirectory( Environment.DIRECTORY_PICTURES), count + "_" + filename.substring(1)); } } Uri sharedImage = FileProvider.getUriForFile(context, "org.quantumbadger.redreader.provider", dst); try { final InputStream cacheFileInputStream = cacheFile.getInputStream(); if (cacheFileInputStream == null) { notifyFailure(CacheRequest.REQUEST_FAILURE_CACHE_MISS, null, null, "Could not find cached image"); return; } General.copyFile(cacheFileInputStream, dst); Intent shareIntent = new Intent(); shareIntent.setAction(Intent.ACTION_SEND); shareIntent.putExtra(Intent.EXTRA_STREAM, sharedImage); shareIntent.setType(mimetype); activity.startActivity(Intent.createChooser(shareIntent, activity.getString(R.string.action_share_image))); } catch (IOException e) { notifyFailure(CacheRequest.REQUEST_FAILURE_STORAGE, e, null, "Could not copy file"); return; } activity.sendBroadcast( new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, sharedImage)); General.quickToast(context, context.getString(R.string.action_save_image_success) + " " + dst.getAbsolutePath()); } }); } @Override public void onNotAnImage() { General.quickToast(activity, R.string.selected_link_is_not_image); } }); }
From source file:com.nextgis.mobile.forms.CameraFragment.java
private File getOutputMediaFile() { // To be safe, you should check that the SDCard is mounted // using Environment.getExternalStorageState() before doing this. File mediaStorageDir = new File(getActivity().getExternalFilesDir(Environment.DIRECTORY_PICTURES), ""); // Create the storage directory if it does not exist if (!mediaStorageDir.exists()) { if (!mediaStorageDir.mkdirs()) { Log.d(TAG, "failed to create directory"); return null; }//from w w w. j ava2s.c o m } // Create a media file name String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date()); fileName = "IMG_" + timeStamp + ".jpg"; imgFile = new File(mediaStorageDir, fileName); return imgFile; }