Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
import java.io.File;

import android.app.Activity;

import android.content.Intent;
import android.net.Uri;
import android.os.Environment;
import android.provider.MediaStore;

public class Main {
    public static final int REQUEST_CROP_RETURN_SELF_CENTER = 6;
    private static File mCropAvatar;
    private static Uri mCropUri;
    private static Activity mActivity;
    public static final String CROP_IMG_PATH = Environment.getExternalStorageDirectory() + "/yourName/crop_temp";

    public static void cropImgFromSelfCenter(Uri uri) {
        Intent intent = new Intent("com.android.camera.action.CROP");
        intent.setDataAndType(uri, "image/*");
        intent.putExtra("crop", "true");
        intent.putExtra("aspectX", 110);
        intent.putExtra("aspectY", 135);
        intent.putExtra("outputX", 110);
        intent.putExtra("outputY", 135);
        intent.putExtra("return-data", false);
        intent.putExtra("noFaceDetection", true);
        File mFile = new File(Environment.getExternalStorageDirectory() + "/yourName");
        if (!mFile.exists())
            mFile.mkdirs();
        mCropAvatar = new File(CROP_IMG_PATH);
        if (mCropAvatar.exists())
            mCropAvatar.delete();
        mCropUri = Uri.fromFile(mCropAvatar);
        intent.putExtra(MediaStore.EXTRA_OUTPUT, mCropUri);
        mActivity.startActivityForResult(intent, REQUEST_CROP_RETURN_SELF_CENTER);
    }
}