繁体   English   中英

捕获照片并存储到内部存储 android

[英]Capture Photo and store to internal storage android

我想从相机或文件中选择图像并将其用于裁剪活动。所以我在外部存储中创建了一个文件并将其传递给相机活动,它可以成功运行。但是当我尝试在内部存储中创建文件并传递它时,无法正常工作.

      AlertDialog.Builder builder = new AlertDialog.Builder(this);
                    builder.setTitle("Add Photo!");
                    builder.setItems(options, new DialogInterface.OnClickListener() {
                        @Override
                        public void onClick(DialogInterface dialog, int item) {
                            if (options[item].equals("Take Photo")) {
                                Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);

                               // File f = new File(Environment.getExternalStorageDirectory(), "temp.jpg");

                                  File f = new File(Environment.getDataDirectory(), "temp.jpg");
                                intent.putExtra(MediaStore.EXTRA_OUTPUT, Uri.fromFile(f));
                                startActivityForResult(intent, 1);
                            } else if (options[item].equals("Choose from Gallery")) {
                                Intent intent = new Intent(Intent.ACTION_PICK, android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI);
                                startActivityForResult(intent, 2);

                            } else if (options[item].equals("Cancel")) {
                                dialog.dismiss();
                            }
                        }
                    });

第三方相机应用程序无法写入应用程序内部存储中的位置(例如getFilesDir() ),因为它们无权访问它。

欢迎您尝试使用FileProvider东西通过content:// Uri公开内部存储上的位置,然后尝试这样做,但我怀疑许多相机应用程序不会期望这样的Uri值。

我所知道的唯一允许您将照片拍摄到内部存储的方法是使用相机 API 并自己拍摄照片,这并不容易。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM