take Photo via Intent - Android android.hardware

Android examples for android.hardware:Photo

Description

take Photo via Intent

Demo Code

import android.app.Activity;
import android.content.ContentValues;
import android.content.Intent;
import android.graphics.Bitmap;
import android.net.Uri;
import android.provider.MediaStore;

public class Main{

    public static final int REQUEST_CODE_TAKE_PHOTO = 0xF1;

    public static Uri takePhoto(Activity activity) {
        Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);// "android.media.action.IMAGE_CAPTURE"

        ContentValues values = new ContentValues();
        Uri photoUri = activity.getContentResolver().insert(
                MediaStore.Images.Media.EXTERNAL_CONTENT_URI, values);
        intent.putExtra(android.provider.MediaStore.EXTRA_OUTPUT, photoUri);
        activity.startActivityForResult(intent, REQUEST_CODE_TAKE_PHOTO);
        return photoUri;
    }//from  ww  w.  j  a v a2s .co  m
    public static Uri takePhoto(android.support.v4.app.Fragment fragment) {

        Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);// "android.media.action.IMAGE_CAPTURE"
 
        ContentValues values = new ContentValues();
        Uri photoUri = fragment
                .getActivity()
                .getContentResolver()
                .insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI,
                        values);
        intent.putExtra(android.provider.MediaStore.EXTRA_OUTPUT, photoUri);
        fragment.startActivityForResult(intent, REQUEST_CODE_TAKE_PHOTO);
        return photoUri;
    }

}

Related Tutorials