Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/229.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 谁能给我一个好的安卓摄像头代码_Android_Android Camera - Fatal编程技术网

Android 谁能给我一个好的安卓摄像头代码

Android 谁能给我一个好的安卓摄像头代码,android,android-camera,Android,Android Camera,我是Android新手,我有一个摄像头代码,可以在三星的duos中正常工作,但是如果我使用micromax,karbon。。。等等,它不工作,在一些手机中,它会打开前摄像头…等等 public static boolean checkCameraHardware(Context context) { if (context.getPackageManager().hasSystemFeature( PackageManager.FEATURE_CAMERA)) {

我是Android新手,我有一个摄像头代码,可以在三星的duos中正常工作,但是如果我使用micromax,karbon。。。等等,它不工作,在一些手机中,它会打开前摄像头…等等

public static boolean checkCameraHardware(Context context) {
    if (context.getPackageManager().hasSystemFeature(
            PackageManager.FEATURE_CAMERA)) {
        // this device has a camera
        return true;
    } else {
        // no camera on this device
        return false;
    }
}  
//摄像机代码

public void openCamera() {

    if (Helper.checkCameraHardware(this)) {
        try {
            SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
            String dateFileName = sdf.format(new Date());

            SimpleDateFormat sdf1 = new SimpleDateFormat("yyyyMMddHHmmss");
            String curentDateandTime = sdf1.format(new Date());

            File sdImageMainDirectory = new File(Environment
                    .getExternalStorageDirectory().getPath()
                    + "/"
                    + Helper.IMG_FOLDER + "/" + dateFileName);
            if (!sdImageMainDirectory.exists()) {
                sdImageMainDirectory.mkdirs();
            }

            String PATH = Environment.getExternalStorageDirectory()
                    .getPath()
                    + "/"
                    + Helper.IMG_FOLDER
                    + "/"
                    + dateFileName + "/";
            // PATH = PATH OF DIRECTORY,image_PATH = full path of IMAGE

            image_PATH = PATH + curentDateandTime + ".jpg";

            System.out.println("image_PATH In open camera" + image_PATH);

            File file = new File(PATH, curentDateandTime + ".jpg");

            Uri outputFileUri = Uri.fromFile(file);

            Intent i = new Intent("android.media.action.IMAGE_CAPTURE");
            i.putExtra(MediaStore.EXTRA_OUTPUT, outputFileUri);
            startActivityForResult(i, 1234);

        } catch (Exception e) {
            Helper.AlertBox(this,
                    "Error No: 001\nPlease contact Bluefrog technical person.\n"
                            + e.toString());
        }
    } else {
        Helper.AlertBox(this, "Image Not Captured.!");
        image_PATH = "";
    }
}

public void onActivityResult(int requestCode, int resultCode, Intent data) {
    // image_PATH = "";
    image_str = "";

    // super.onActivityResult(requestCode, resultCode, data);

    if (requestCode == 1234) {
        if (resultCode == RESULT_OK) {
            // restorePreferences();

            Log.e("image_PATH in OnActivityResultSet", "File exist at "
                    + image_PATH);

            File file = new File(image_PATH);
            if (file.exists()) {

                Log.e("File exist condition :", "File exist at "
                        + image_PATH);

                try {

                    iv_MEPhoto.setImageBitmap(Helper.getImage(file
                            .getPath()));
                    iv_MEPhoto.setVisibility(View.VISIBLE);
                    photoTaken = true;
                    SENDING_IMAGE_PATH = image_PATH;

                    Log.e("File exist condition :", "File exist at "
                            + image_PATH);

                } catch (Exception e) {
                    Helper.AlertBox(this,
                            "Error No: 004\nPlease contact Bluefrog technical person.\n"
                                    + e.toString());
                    Log.e("Error reading file", e.toString());
                }

            } else {
                Helper.AlertBox(this,
                        "Error No: 005\nPlease contact Bluefrog technical person.");
            }
        } else {
            image_PATH = "";
            Helper.AlertBox(this, "Image Not Captured.");

        }
    }

}
申报-

 public static final int CAPTURE_IMAGE_FULLSIZE_ACTIVITY_REQUEST_CODE = 1777;   
然后在oncreate()方法中使用

photoimage=(ImageButton)findViewById(R.id.photobutton); setOnClickListener(新的OnClickListener(){

然后在外部创建写

 protected void onActivityResult(int requestCode, int resultCode, Intent data) {

         if (requestCode == CAPTURE_IMAGE_FULLSIZE_ACTIVITY_REQUEST_CODE&& resultCode == RESULT_OK) 
            {


               File file = new File(Environment.getExternalStorageDirectory()+File.separator + "image.jpg");
               Bitmap bitmap1 = decodeSampledBitmapFromFile(file.getAbsolutePath(), 1500, 800);
              // System.out.println("hight "+bitmap.getHeight() +"width "+bitmap.getWidth());
                 Matrix  matrix = new Matrix();

                //set image rotation value to 45 degrees in matrix.
                matrix.postRotate(0);

                //Create bitmap with new values.
                Bitmap bitmap = Bitmap.createBitmap( bitmap1, 0, 0,
                         bitmap1.getWidth(),  bitmap1.getHeight(), matrix, true);


        }
    }

您是否指定了摄像头的权限?是的,还添加了以下内容:上述代码工作正常,但如果我使用micromax,它将不工作,并且在某些手机中它将打开前摄像头..等等,我没有使用过,但仍然工作。是否必须使用?调试并查看问题出在哪里
 protected void onActivityResult(int requestCode, int resultCode, Intent data) {

         if (requestCode == CAPTURE_IMAGE_FULLSIZE_ACTIVITY_REQUEST_CODE&& resultCode == RESULT_OK) 
            {


               File file = new File(Environment.getExternalStorageDirectory()+File.separator + "image.jpg");
               Bitmap bitmap1 = decodeSampledBitmapFromFile(file.getAbsolutePath(), 1500, 800);
              // System.out.println("hight "+bitmap.getHeight() +"width "+bitmap.getWidth());
                 Matrix  matrix = new Matrix();

                //set image rotation value to 45 degrees in matrix.
                matrix.postRotate(0);

                //Create bitmap with new values.
                Bitmap bitmap = Bitmap.createBitmap( bitmap1, 0, 0,
                         bitmap1.getWidth(),  bitmap1.getHeight(), matrix, true);


        }
    }