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:com.fa.mastodon.fragment.ViewMediaFragment.java
private void downloadImage() { //Permission stuff if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN && ContextCompat.checkSelfPermission(this.getContext(), android.Manifest.permission.WRITE_EXTERNAL_STORAGE) != PackageManager.PERMISSION_GRANTED) { android.support.v4.app.ActivityCompat.requestPermissions(getActivity(), new String[] { android.Manifest.permission.WRITE_EXTERNAL_STORAGE }, PERMISSIONS_REQUEST_WRITE_EXTERNAL_STORAGE); } else {/*from w w w. jav a2s .c o m*/ //download stuff String url = getArguments().getString("url"); Uri uri = Uri.parse(url); String filename = new File(url).getName(); DownloadManager downloadManager = (DownloadManager) getContext() .getSystemService(Context.DOWNLOAD_SERVICE); DownloadManager.Request request = new DownloadManager.Request(uri); request.allowScanningByMediaScanner(); request.setDestinationInExternalPublicDir(Environment.DIRECTORY_PICTURES, getString(R.string.app_name) + "/" + filename); downloadManager.enqueue(request); } }
From source file:com.grokkingandroid.sampleapp.samples.data.contentprovider.lentitems.LentItemDisplayFragment.java
/** * The dummyApplyBatch method is only used to show a sample batch. * It's not used within this sample app. *//* w w w.j a va2 s. co m*/ @SuppressWarnings("unused") private void dummyApplyBatch() { String borrower = "John Doe"; String item = "Anhalter"; boolean hasPic = true; Context ctx = getActivity(); String somePath = ctx.getExternalFilesDir(Environment.DIRECTORY_PICTURES).getAbsolutePath(); ArrayList<ContentProviderOperation> ops = new ArrayList<ContentProviderOperation>(); ops.add(ContentProviderOperation.newInsert(Items.CONTENT_URI).withValue(Items.NAME, item) .withValue(Items.BORROWER, borrower).build()); if (hasPic) { ops.add(ContentProviderOperation.newInsert(Photos.CONTENT_URI).withValue(Photos._DATA, somePath) .withValueBackReference(Photos.ITEMS_ID, 0).build()); } try { ContentResolver resolver = getActivity().getContentResolver(); resolver.applyBatch(LentItemsContract.AUTHORITY, ops); } catch (OperationApplicationException e) { Log.e("wemonit", "cannot apply batch: " + e.getLocalizedMessage(), e); } catch (RemoteException e) { Log.e("wemonit", "cannot apply batch: " + e.getLocalizedMessage(), e); } // EventBus.getDefault().post(whatever); }
From source file:com.dexin.MainActivity.java
public File getCameraFile() { File dir = getExternalFilesDir(Environment.DIRECTORY_PICTURES); return new File(dir, FILE_NAME); }
From source file:camera.AnotherCamera.java
/** * Creates the image file to which the image must be saved. * @return//from www .j a va 2 s.c o m * @throws IOException */ protected File createImageFile() throws IOException { // 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, /* prefix */ ".jpg", /* suffix */ storageDir /* directory */ ); // Save a file: path for use with ACTION_VIEW intents CameraActivity activity = (CameraActivity) getActivity(); activity.setCurrentPhotoPath("file:" + image.getAbsolutePath()); return image; }
From source file:com.anyline.reactnative.DocumentActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(getResources().getIdentifier("activity_scan_document", "layout", getPackageName())); //Set the flag to keep the screen on (otherwise the screen may go dark during scanning) getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); imageViewResult = (ImageView) findViewById( getResources().getIdentifier("image_result", "id", getPackageName())); errorMessageLayout = (FrameLayout) findViewById( getResources().getIdentifier("error_message_layout", "id", getPackageName())); errorMessage = (TextView) findViewById( getResources().getIdentifier("error_message", "id", getPackageName())); documentScanView = (DocumentScanView) findViewById( getResources().getIdentifier("document_scan_view", "id", getPackageName())); // add a camera open listener that will be called when the camera is opened or an error occurred // this is optional (if not set a RuntimeException will be thrown if an error occurs) documentScanView.setCameraOpenListener(this); // the view can be configured via a json file in the assets, and this config is set here // (alternatively it can be configured via xml, see the Energy Example for that) JSONObject jsonObject;//from w ww . j a v a2 s .c o m try { jsonObject = new JSONObject(configJson); } catch (Exception e) { //JSONException or IllegalArgumentException is possible, return it to javascript finishWithError("error_invalid_json_data"); return; } documentScanView.setConfig(new AnylineViewConfig(this, jsonObject)); // Optional: Set a ratio you want the documents to be restricted to. default is set to DIN_AX documentScanView.setDocumentRatios(DocumentScanView.DocumentRatio.DIN_AX_PORTRAIT.getRatio()); // Optional: Set a maximum deviation for the ratio. 0.15 is the default documentScanView.setMaxDocumentRatioDeviation(0.15); // initialize Anyline with the license key and a Listener that is called if a result is found documentScanView.initAnyline(licenseKey, new DocumentResultListener() { @Override public void onResult(DocumentResult documentResult) { // handle the result document images here if (progressDialog != null && progressDialog.isShowing()) { progressDialog.dismiss(); } AnylineImage transformedImage = documentResult.getResult(); AnylineImage fullFrame = documentResult.getFullImage(); imageViewResult .setImageBitmap(Bitmap.createScaledBitmap(transformedImage.getBitmap(), 100, 160, false)); /** * IMPORTANT: cache provided frames here, and release them at the end of this onResult. Because * keeping them in memory (e.g. setting the full frame to an ImageView) * will result in a OutOfMemoryError soon. This error is reported in {@link #onTakePictureError * (Throwable)} * * Use a DiskCache http://developer.android.com/training/displaying-bitmaps/cache-bitmap.html#disk-cache * for example * */ File outDir = new File(getExternalFilesDir(Environment.DIRECTORY_PICTURES), "ok"); outDir.mkdir(); // change the file ending to png if you want a png File outFile = new File(outDir, "" + System.currentTimeMillis() + ".jpg"); try { // convert the transformed image into a gray scaled image internally // transformedImage.getGrayCvMat(false); // get the transformed image as bitmap // Bitmap bmp = transformedImage.getBitmap(); // save the image with quality 100 (only used for jpeg, ignored for png) transformedImage.save(outFile, 100); showToast(getString( getResources().getIdentifier("document_image_saved_to", "string", getPackageName())) + " " + outFile.getAbsolutePath()); } catch (IOException e) { e.printStackTrace(); } // release the images transformedImage.release(); fullFrame.release(); JSONObject jsonResult = new JSONObject(); try { jsonResult.put("imagePath", outFile.getAbsolutePath()); jsonResult.put("outline", jsonForOutline(documentResult.getOutline())); jsonResult.put("confidence", documentResult.getConfidence()); } catch (Exception jsonException) { //should not be possible Log.e(TAG, "Error while putting image path to json.", jsonException); } Boolean cancelOnResult = true; JSONObject jsonObject; try { jsonObject = new JSONObject(configJson); cancelOnResult = jsonObject.getBoolean("cancelOnResult"); } catch (Exception e) { } if (cancelOnResult) { ResultReporter.onResult(jsonResult, true); setResult(AnylineSDKPlugin.RESULT_OK); finish(); } else { ResultReporter.onResult(jsonResult, false); } } @Override public void onPreviewProcessingSuccess(AnylineImage anylineImage) { // this is called after the preview of the document is completed, and a full picture will be // processed automatically } @Override public void onPreviewProcessingFailure(DocumentScanView.DocumentError documentError) { // this is called on any error while processing the document image // Note: this is called every time an error occurs in a run, so that might be quite often // An error message should only be presented to the user after some time showErrorMessageFor(documentError); } @Override public void onPictureProcessingFailure(DocumentScanView.DocumentError documentError) { showErrorMessageFor(documentError, true); if (progressDialog != null && progressDialog.isShowing()) { progressDialog.dismiss(); } // if there is a problem, here is how images could be saved in the error case // this will be a full, not cropped, not transformed image AnylineImage image = documentScanView.getCurrentFullImage(); if (image != null) { File outDir = new File(getExternalFilesDir(Environment.DIRECTORY_PICTURES), "error"); outDir.mkdir(); File outFile = new File(outDir, "" + System.currentTimeMillis() + documentError.name() + ".jpg"); try { image.save(outFile, 100); Log.d(TAG, "error image saved to " + outFile.getAbsolutePath()); } catch (IOException e) { e.printStackTrace(); } image.release(); } } @Override public boolean onDocumentOutlineDetected(List<PointF> list, boolean documentShapeAndBrightnessValid) { // is called when the outline of the document is detected. return true if the outline is consumed by // the implementation here, false if the outline should be drawn by the DocumentScanView lastOutline = list; // saving the outline for the animations return false; } @Override public void onTakePictureSuccess() { // this is called after the image has been captured from the camera and is about to be processed progressDialog = ProgressDialog.show(DocumentActivity.this, getString(getResources().getIdentifier("document_processing_picture_header", "string", getPackageName())), getString(getResources().getIdentifier("document_processing_picture", "string", getPackageName())), true); if (errorMessageAnimator != null && errorMessageAnimator.isRunning()) { handler.post(new Runnable() { @Override public void run() { errorMessageAnimator.cancel(); errorMessageLayout.setVisibility(View.GONE); } }); } } @Override public void onTakePictureError(Throwable throwable) { // This is called if the image could not be captured from the camera (most probably because of an // OutOfMemoryError) throw new RuntimeException(throwable); } }); // optionally stop the scan once a valid result was returned // documentScanView.setCancelOnResult(cancelOnResult); }
From source file:io.anyline.cordova.DocumentActivity.java
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(getResources().getIdentifier("activity_scan_document", "layout", getPackageName())); //Set the flag to keep the screen on (otherwise the screen may go dark during scanning) getWindow().addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON); imageViewResult = (ImageView) findViewById( getResources().getIdentifier("image_result", "id", getPackageName())); errorMessageLayout = (FrameLayout) findViewById( getResources().getIdentifier("error_message_layout", "id", getPackageName())); errorMessage = (TextView) findViewById( getResources().getIdentifier("error_message", "id", getPackageName())); documentScanView = (DocumentScanView) findViewById( getResources().getIdentifier("document_scan_view", "id", getPackageName())); // add a camera open listener that will be called when the camera is opened or an error occurred // this is optional (if not set a RuntimeException will be thrown if an error occurs) documentScanView.setCameraOpenListener(this); // the view can be configured via a json file in the assets, and this config is set here // (alternatively it can be configured via xml, see the Energy Example for that) JSONObject jsonObject;//from ww w .java2 s .c o m try { jsonObject = new JSONObject(configJson); } catch (Exception e) { //JSONException or IllegalArgumentException is possible, return it to javascript finishWithError(Resources.getString(this, "error_invalid_json_data") + "\n" + e.getLocalizedMessage()); return; } documentScanView.setConfig(new AnylineViewConfig(this, jsonObject)); // Optional: Set a ratio you want the documents to be restricted to. default is set to DIN_AX documentScanView.setDocumentRatios(DocumentScanView.DocumentRatio.DIN_AX_PORTRAIT.getRatio()); // Optional: Set a maximum deviation for the ratio. 0.15 is the default documentScanView.setMaxDocumentRatioDeviation(0.15); // initialize Anyline with the license key and a Listener that is called if a result is found documentScanView.initAnyline(licenseKey, new DocumentResultListener() { @Override public void onResult(AnylineImage transformedImage, AnylineImage fullFrame, List<PointF> documentOutline) { // handle the result document images here if (progressDialog != null && progressDialog.isShowing()) { progressDialog.dismiss(); } imageViewResult .setImageBitmap(Bitmap.createScaledBitmap(transformedImage.getBitmap(), 100, 160, false)); /** * IMPORTANT: cache provided frames here, and release them at the end of this onResult. Because * keeping them in memory (e.g. setting the full frame to an ImageView) * will result in a OutOfMemoryError soon. This error is reported in {@link #onTakePictureError * (Throwable)} * * Use a DiskCache http://developer.android.com/training/displaying-bitmaps/cache-bitmap.html#disk-cache * for example * */ File outDir = new File(getExternalFilesDir(Environment.DIRECTORY_PICTURES), "ok"); outDir.mkdir(); // change the file ending to png if you want a png File outFile = new File(outDir, "" + System.currentTimeMillis() + ".jpg"); try { // convert the transformed image into a gray scaled image internally // transformedImage.getGrayCvMat(false); // get the transformed image as bitmap // Bitmap bmp = transformedImage.getBitmap(); // save the image with quality 100 (only used for jpeg, ignored for png) transformedImage.save(outFile, 100); showToast(getString( getResources().getIdentifier("document_image_saved_to", "string", getPackageName())) + " " + outFile.getAbsolutePath()); } catch (IOException e) { e.printStackTrace(); } // release the images transformedImage.release(); fullFrame.release(); JSONObject jsonResult = new JSONObject(); try { jsonResult.put("imagePath", outFile.getAbsolutePath()); } catch (Exception jsonException) { //should not be possible Log.e(TAG, "Error while putting image path to json.", jsonException); } Boolean cancelOnResult = true; JSONObject jsonObject; try { jsonObject = new JSONObject(configJson); cancelOnResult = jsonObject.getBoolean("cancelOnResult"); } catch (Exception e) { } if (cancelOnResult) { ResultReporter.onResult(jsonResult, true); setResult(AnylinePlugin.RESULT_OK); finish(); } else { ResultReporter.onResult(jsonResult, false); } } @Override public void onPreviewProcessingSuccess(AnylineImage anylineImage) { // this is called after the preview of the document is completed, and a full picture will be // processed automatically } @Override public void onPreviewProcessingFailure(DocumentScanView.DocumentError documentError) { // this is called on any error while processing the document image // Note: this is called every time an error occurs in a run, so that might be quite often // An error message should only be presented to the user after some time showErrorMessageFor(documentError); } @Override public void onPictureProcessingFailure(DocumentScanView.DocumentError documentError) { showErrorMessageFor(documentError, true); if (progressDialog != null && progressDialog.isShowing()) { progressDialog.dismiss(); } // if there is a problem, here is how images could be saved in the error case // this will be a full, not cropped, not transformed image AnylineImage image = documentScanView.getCurrentFullImage(); if (image != null) { File outDir = new File(getExternalFilesDir(Environment.DIRECTORY_PICTURES), "error"); outDir.mkdir(); File outFile = new File(outDir, "" + System.currentTimeMillis() + documentError.name() + ".jpg"); try { image.save(outFile, 100); Log.d(TAG, "error image saved to " + outFile.getAbsolutePath()); } catch (IOException e) { e.printStackTrace(); } image.release(); } } @Override public boolean onDocumentOutlineDetected(List<PointF> list, boolean documentShapeAndBrightnessValid) { // is called when the outline of the document is detected. return true if the outline is consumed by // the implementation here, false if the outline should be drawn by the DocumentScanView lastOutline = list; // saving the outline for the animations return false; } @Override public void onTakePictureSuccess() { // this is called after the image has been captured from the camera and is about to be processed progressDialog = ProgressDialog.show(DocumentActivity.this, getString(getResources().getIdentifier("document_processing_picture_header", "string", getPackageName())), getString(getResources().getIdentifier("document_processing_picture", "string", getPackageName())), true); if (errorMessageAnimator != null && errorMessageAnimator.isRunning()) { handler.post(new Runnable() { @Override public void run() { errorMessageAnimator.cancel(); errorMessageLayout.setVisibility(View.GONE); } }); } } @Override public void onTakePictureError(Throwable throwable) { // This is called if the image could not be captured from the camera (most probably because of an // OutOfMemoryError) throw new RuntimeException(throwable); } }); // optionally stop the scan once a valid result was returned // documentScanView.setCancelOnResult(cancelOnResult); }
From source file:com.poinsart.votar.VotarMain.java
/** Create a File for saving an image or video */ @SuppressLint("SimpleDateFormat") private static File getOutputMediaFile(int type) { // To be safe, you should check that the SDCard is mounted // using Environment.getExternalStorageState() before doing this. File mediaStorageDir = new File( Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES), "VotAR"); // 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.w("VotAR camera", "failed to create directory"); return null; }// w w w . j av a2s . co m } // Create a media file name String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date()); File mediaFile; if (type == MEDIA_TYPE_IMAGE) { mediaFile = new File(mediaStorageDir.getPath() + File.separator + "IMG_" + timeStamp + ".jpg"); } else if (type == MEDIA_TYPE_VIDEO) { mediaFile = new File(mediaStorageDir.getPath() + File.separator + "VID_" + timeStamp + ".mp4"); } else { return null; } return mediaFile; }
From source file:com.renard.ocr.BaseDocumentActivitiy.java
protected void startCamera() { try {// ww w . java2 s. c o m cameraPicUri = null; dateCameraIntentStarted = new Date(); Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); // 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 = null; try { if (!storageDir.exists()) { storageDir.mkdirs(); } image = new File(storageDir, imageFileName + ".jpg"); if (image.exists()) { image.createNewFile(); } cameraPicUri = Uri.fromFile(image); intent.putExtra(MediaStore.EXTRA_OUTPUT, cameraPicUri); startActivityForResult(intent, REQUEST_CODE_MAKE_PHOTO); } catch (IOException e) { showFileError(PixLoadStatus.IO_ERROR); } } catch (ActivityNotFoundException e) { showFileError(PixLoadStatus.CAMERA_APP_NOT_FOUND); } }
From source file:it.smartcampuslab.riciclo.FeedbackFragment.java
private void startCamera() { Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); File mediaStorageDir = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES); intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(new File(mediaStorageDir + File.separator + "tmpImg.jpg"))); startActivityForResult(Intent.createChooser(intent, getString(R.string.feedback_capture)), 100); }
From source file:com.mygaadi.imageselectorlibrary.camera2.Camera2BasicFragment.java
private static File getOutputMediaFile(int type) { File mediaStorageDir = new File( Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES), "ImageSelectorLibrary"); if (Utility.checkForExternalDirectory(mediaStorageDir)) { return null; }/*from ww w . ja v a 2 s . c o m*/ // Create a media file name String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date()); File mediaFile; if (type == MEDIA_TYPE_IMAGE) { mediaFile = new File(mediaStorageDir.getPath() + File.separator + "IMG_" + timeStamp + ".jpg"); } else { return null; } return mediaFile; }