从前置摄像头拍摄照片并保存,无需按钮拍照或保存

时间:2017-06-22 13:46:02

标签: android camera

我想从前置摄像头拍摄照片,没有任何按钮拍照并自动保存

我的代码:

final String dir = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS) + "/picFolder/";
                            File newdir = new File(dir);
                            newdir.mkdirs();
                            String file2 = dir+"test.jpg";
                            File newfile = new File(file2);
                            try {
                                newfile.createNewFile();
                            }
                            catch (IOException e)
                            {
                            }

                            File image = new File(dir, "image.jpg");
                            Uri uriSavedImage = Uri.fromFile(image);
                            Intent imageIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
                            imageIntent.putExtra(MediaStore.EXTRA_OUTPUT, uriSavedImage);
                            startActivityForResult(imageIntent, 0);

0 个答案:

没有答案