Android Photo Take takePhoto(final Activity activity, final String dir, final String filename, final int cmd)

Here you can find the source of takePhoto(final Activity activity, final String dir, final String filename, final int cmd)

Description

take Photo

Declaration

public static boolean takePhoto(final Activity activity,
            final String dir, final String filename, final int cmd) 

Method Source Code

//package com.java2s;

import java.io.File;

import android.app.Activity;
import android.content.ActivityNotFoundException;

import android.content.Intent;

import android.net.Uri;
import android.provider.MediaStore;

public class Main {
    private static String filePath = null;

    public static boolean takePhoto(final Activity activity,
            final String dir, final String filename, final int cmd) {
        filePath = dir + filename;//w w w  . j  a va 2 s .  c o m

        final Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
        final File cameraDir = new File(dir);
        if (!cameraDir.exists()) {
            return false;
        }

        final File file = new File(filePath);
        final Uri outputFileUri = Uri.fromFile(file);
        intent.putExtra(MediaStore.EXTRA_OUTPUT, outputFileUri);
        try {
            activity.startActivityForResult(intent, cmd);

        } catch (final ActivityNotFoundException e) {
            return false;
        }
        return true;
    }
}