Android ACTION_IMAGE_CAPTURE with EXTRA_OUTPUT in internal memory

When I take a photo from the camera, if I call

File file = new File(getFilesDir().getAbsolutePath() + "/myImage.jpg"); Uri outputFileUri = Uri.fromFile(file); cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE); cameraIntent.putExtra(MediaStore.EXTRA_OUTPUT, outputFileUri); 

OK button on the camera application does not work, it just does nothing (in fact, it does not save it in the internal memory, I assumed, and therefore the application itself does nothing).

If I however call

 File file = new File(Environment.getExternalStorageDirectory().getAbsolutePath() + "/myImage.jpg"); Uri outputFileUri = Uri.fromFile(file); cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE); cameraIntent.putExtra(MediaStore.EXTRA_OUTPUT, outputFileUri); 

everything is in order, and the photo is stored on the SDCard.

My question is: is there a way to save the capture photo in full screen without an SDCard?

+4
source share
3 answers

The native camera application cannot save the image in the personal internal directories of the application, since it is available only for your specific application.

Instead, you can create custom camera activity to save images to internal directories, or you need to use a camera application with external storage.

Note. If you plan to create custom camera activity, make sure you aim at least 2.3 and higher. Anything below this sign is very difficult to work with.

+9
source

Camera activity will not be able to save the file in the directory of personal activity files, so it fails. You can move the image from external storage to dir files in onActivityResult.

+5
source

This is possible using the file provider. Please refer sample

  public getOutputUri(@NonNull Context pContext) { String photo = photo.jpeg;//your file name File photoFile = new File(pContext.getFilesDir(), photo); Uri lProviderPath = FileProvider.getUriForFile(pContext, pContext.getApplicationContext() .getPackageName() + ".provider", photoFile); return lProviderPath; } private void capturePhoto() { Intent cameraIntent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE); cameraIntent.putExtra(MediaStore.EXTRA_OUTPUT, getOutputUri(this)); cameraIntent.setFlags(Intent.FLAG_GRANT_READ_URI_PERMISSION); startActivityForResult(cameraIntent, 1); } 

Refer to the following Android document for more information https://developer.android.com/reference/android/support/v4/content/FileProvider

0
source

Source: https://habr.com/ru/post/1446282/


All Articles