Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
import android.app.Activity;

import android.content.ContentValues;
import android.content.Context;
import android.content.Intent;

import android.os.Environment;
import android.provider.MediaStore;
import android.widget.Toast;

public class Main {
    public static void openCamera(Context context, int code) {
        if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) {
            Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE).putExtra(MediaStore.EXTRA_OUTPUT,
                    context.getContentResolver().insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI,
                            new ContentValues()));
            // intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(new File(Environment.getExternalStorageDirectory() + imagePath)));
            ((Activity) context).startActivityForResult(intent, code);

        } else
            Toast.makeText(context, "no sdcard!", Toast.LENGTH_SHORT).show();
    }
}