Skip to content Skip to sidebar Skip to footer

Uploading Image (action_image_capture) To Firebase Storage

EDIT: The discussion on this issue has been carried to another question: Image capture with camera & upload to Firebase (Uri in onActivityResult() is null) PLEASE check it out!

Solution 1:

You need to re-read the documentation and follow the example to create a file and store its Uri in the image capture intent. This is the code from the documentation you need to add:

String mCurrentPhotoPath;

private File createImageFile()throws IOException {
    // Create an image file nameStringtimeStamp=newSimpleDateFormat("yyyyMMdd_HHmmss").format(newDate());
    StringimageFileName="JPEG_" + timeStamp + "_";
    FilestorageDir= getExternalFilesDir(Environment.DIRECTORY_PICTURES);
    Fileimage= File.createTempFile(
        imageFileName,  /* prefix */".jpg",         /* suffix */
        storageDir      /* directory */
    );

    // Save a file: path for use with ACTION_VIEW intents
    mCurrentPhotoPath = image.getAbsolutePath();
    return image;
}

privatevoiddispatchTakePictureIntent() {
    IntenttakePictureIntent=newIntent(MediaStore.ACTION_IMAGE_CAPTURE);
    // Ensure that there's a camera activity to handle the intentif (takePictureIntent.resolveActivity(getPackageManager()) != null) {
        // Create the File where the photo should goFilephotoFile=null;
        try {
            photoFile = createImageFile();
        } catch (IOException ex) {
            // Error occurred while creating the File
            ...
        }
        // Continue only if the File was successfully createdif (photoFile != null) {
            UriphotoURI= FileProvider.getUriForFile(this,
                                                  "com.example.android.fileprovider",
                                                  photoFile);
            takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, photoURI);
            startActivityForResult(takePictureIntent, REQUEST_TAKE_PHOTO);
        }
    }
}


b_capture.setOnClickListener(newView.OnClickListener() {
        @OverridepublicvoidonClick(View view) {
            dispatchTakePictureIntent()

            //Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);//startActivityForResult(intent, CAMERA_REQUEST_CODE);
        }
    });

Solution 2:

Question solved in the following discussion: Image capture with camera & upload to Firebase (Uri in onActivityResult() is null) Thanks to everyone who participated!

Post a Comment for "Uploading Image (action_image_capture) To Firebase Storage"