There is option of capture image from camera in my application.But there is problem to get image from camera. When i use ACTION_IMAGE_CAPTURE
this it return nul
You're probably running a Samsung device. I believe this is a bug that occurs in these devices. You have to get the URI otherwise. Do this:
/**
* (This is a variable instance) Contains the path and file name where you want to save the image.
* Mainly used to start Intent.Action_View with this URI. (GalleryApp)
*/
private Uri uriImage= null;
public void onClickCamera(View v){
// Cria uma intent para capturar uma imagem e retorna o controle para quem o chamou (NAO PRECISA DECLARAR PERMISSAO NO MANIFESTO PARA ACESSAR A CAMERA POIS O FAZEMOS VIA INTENT).
// Creates an intent to capture an image and returns control to the caller
Intent intent = new Intent( MediaStore.ACTION_IMAGE_CAPTURE );
// Cria um arquivo para salvar a imagem.
// Creates an file to save the image.
uriImage = ProcessaImagens.getOutputMediaFileUri( ProcessaImagens.MEDIA_TYPE_IMAGE, getActivity().getApplicationContext() );
// Intent to pass a URI object containing the path and file name where you want to save the image. We'll get through the data parameter of the method onActivityResult().
intent.putExtra( MediaStore.EXTRA_OUTPUT, uriImagem );
// Starts the intent to image capture and waits the result.
startActivityForResult( intent, CAPTURE_IMAGE_ACTIVITY_REQUEST_CODE );
}
The ProcessaImagens class is a class that I coded and I'm sharing with everyone. Can use this class to facilitate. It has a very good method to compress the image if you want to save images in the database. In its onActivityResult()
method do this:
@Override
public void onActivityResult( int requestCode, int resultCode, Intent data ) {
// If finished activity on startForActivityResult.
if ( resultCode == Activity.RESULT_OK ) {
if ( requestCode == CAPTURE_IMAGE_ACTIVITY_REQUEST_CODE ) {
String imagePath = uriImage.getPath();
// I will compress the imagem. Read the javadoc from method and you'll see which it returns both bitmap and array bytes.
List
Note that I used getActivity().getApplicationContext()
because I'm getting the context from a Fragment and not from Activity. I believe with this method you can have what you want. Just make little changes how form to get context.