Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
//License from project: Open Source License 

import android.content.Context;
import android.content.pm.PackageManager;
import android.hardware.Camera;

import android.widget.Toast;

public class Main {
    public static Camera getCameraInstance(Context context) {
        Camera c = null;
        try {
            if (checkCameraHardware(context)) {
                c = Camera.open();
            }
        } catch (Exception e) {
            Toast.makeText(context, "Camera is not available", Toast.LENGTH_SHORT).show();
        }
        return c;
    }

    public static boolean checkCameraHardware(Context context) {
        if (context.getPackageManager().hasSystemFeature(PackageManager.FEATURE_CAMERA)) {
            return true;
        } else {
            Toast.makeText(context, "No camera on this device", Toast.LENGTH_SHORT).show();
            return false;
        }
    }
}