public void camera() { Intent intent = null; // 判断存储卡是否可以用,可用进行存储 if (StorageUtils.hasSdcard()) { //设定拍照存放到自己指定的目录,可以先建好 File file = new File(savePath); if(!file.exists()){ file.mkdirs(); } Uri pictureUri; File pictureFile = new File(savePath, tempFileName); if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) { intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); ContentValues contentValues = new ContentValues(1); contentValues.put(MediaStore.Images.Media.DATA, pictureFile.getAbsolutePath()); pictureUri = getContentResolver().insert(MediaStore.Images.Media.EXTERNAL_CONTENT_URI,contentValues); }else { intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE); pictureUri = Uri.fromFile(pictureFile); } if (intent != null) { intent.putExtra(MediaStore.EXTRA_OUTPUT, pictureUri); startActivityForResult(intent, 1); } } }
拍照存储文件到相册
最新推荐文章于 2023-02-15 12:47:28 发布