Search code examples
javaandroidandroid-camera-intent

Open Camera Button is saved in the final png screenshot


I created an app to take photos using mobile's camera, show GPS coordinates as a text, and save the image to mobile's gallery. The problem is that the final screenshot saved in mobile's picture gallery contains the "Open Camera" BUTTON. How can I remove it from the screenshot (png) saved?

enter image description here

This is my code:

       /* capture image */

         private void captureImage() {
        Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);

    File photoFile = null;
    try {
        photoFile = createImageFile();
    }
    catch (IOException e) {
        e.printStackTrace();
    }
    //fileUri = getOutputMediaFileUri(MEDIA_TYPE_IMAGE);
    String authorities = getApplicationContext().getPackageName() + ".provider";
    Uri imageUri = FileProvider.getUriForFile(this, authorities, photoFile);
    intent.putExtra(MediaStore.EXTRA_OUTPUT, imageUri);

    // start the image capture Intent
    startActivityForResult(intent, CAMERA_CAPTURE_IMAGE_REQUEST_CODE);

}

/* create image file to store photo */
  String mCurrentPhotoPath;
   private File createImageFile() throws IOException {
    // Create an image file name
    String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss").format(new Date());
    String imageFileName = "JPEG_" + timeStamp + "_";
    File storageDir = getExternalFilesDir(Environment.DIRECTORY_PICTURES);
    File image = File.createTempFile(
            imageFileName,  /* prefix */
            ".jpg",         /* suffix */
            storageDir      /* directory */
    );         // Save a file: path for use with ACTION_VIEW intents
    mCurrentPhotoPath = image.getAbsolutePath();
    return image;
}

Where to add the openCameraButton.setVisibility(View.GONE); and openCameraButton.setVisibility(View.VISIBLE); ? Is there any way to NOT store my image to the mobile's default pictures directory after taking photo ?


Solution

  • Based on the description and the photo you've attached, we can assume that this button opens the phone's camera and (probably) takes a picture. If that's true, you can hide the visibility of the button before the screenshot is taken with openCameraButton.setVisibility(View.GONE); and show the button again, once you've taken the screenshot: openCameraButton.setVisibility(View.VISIBLE);