Android Intent Create PhotoIntent(Activity activity)

Here you can find the source of PhotoIntent(Activity activity)

Description

Photo Intent

Declaration

public static void PhotoIntent(Activity activity) 

Method Source Code

//package com.java2s;
import java.io.File;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;
import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Environment;
import android.provider.MediaStore;
import android.util.Log;

public class Main {
    public static final int MEDIA_TYPE_IMAGE = 1;
    public static final int MEDIA_TYPE_VIDEO = 2;
    private static final int CAPTURE_IMAGE_ACTIVITY_REQUEST_CODE = 100;

    public static void PhotoIntent(Activity activity) {
        Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
        Uri fileUri = getOutputMediaFileUri(MEDIA_TYPE_IMAGE);
        intent.putExtra(MediaStore.EXTRA_OUTPUT, fileUri);
        activity.startActivityForResult(intent,
                CAPTURE_IMAGE_ACTIVITY_REQUEST_CODE);
    }//from  ww w .ja  v a  2s  . c o  m

    private static Uri getOutputMediaFileUri(int type) {
        return Uri.fromFile(getOutputMediaFile(type));
    }

    private static File getOutputMediaFile(int type) {
        if (Environment.getExternalStorageState() == null) {
            return null;
        }
        File mediaStorageDir = new File(
                Environment
                        .getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES),
                "MyCameraApp");
        if (!mediaStorageDir.exists()) {
            if (!mediaStorageDir.mkdirs()) {
                Log.d("MyCameraApp", "failed to create directory");
                return null;
            }
        }
        String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss",
                Locale.US).format(new Date());
        File mediaFile;
        if (type == MEDIA_TYPE_IMAGE) {
            mediaFile = new File(mediaStorageDir.getPath() + File.separator
                    + "IMG_" + timeStamp + ".jpg");
        } else if (type == MEDIA_TYPE_VIDEO) {
            mediaFile = new File(mediaStorageDir.getPath() + File.separator
                    + "VID_" + timeStamp + ".mp4");
        } else {
            return null;
        }

        return mediaFile;
    }
}

Related

  1. shareImages(Activity activity, String imagePath)
  2. pickNcapture(Activity activity, Uri outputFileUri)
  3. organizeAndStart(Activity activity, Class classes, Map paramMap)
  4. onKeyBackGoHome(Activity activity, int keyCode, KeyEvent event)
  5. makeCall(Activity activity, String telNumber)
  6. VideoIntent(Activity activity)
  7. call(String aPhoneNumber, Activity aActivity)
  8. intentSysDefault(Activity activity, Class classes, Map paramMap)
  9. audioBecomingNoisy(Context c)