简体   繁体   English

相机拍摄的两张图像,无法从DCIM / Camera文件夹中删除一张

[英]Two images captured by camera and not able to delete one from DCIM/Camera folder

I'm capturing image from my Nougat device, and I'm storing image in ABC folder, works fine. 我正在从Nougat设备捕获图像,并且将图像存储在ABC文件夹中,效果很好。 After capturing image I'm sending them to server and once it get uploaded I'm deleting images from ABC folder till here it works fine, But I have noticed camera is creating two images one stored in ABC folder and another one in DCIM/Camera folder. 捕获图像后,我将它们发送到服务器,一旦上传,就从ABC文件夹中删除图像,直到它可以正常工作为止,但是我注意到相机正在创建两个图像,一个图像存储在ABC文件夹中,另一个在DCIM / Camera中存储夹。 Also I'm specifying the name of captured image while saving, but one in DCIM/Camera has system generated name, Please guide how to delete that image from DCIM/Camera folder Here is my code 另外我在保存时指定了捕获图像的名称,但是DCIM / Camera中的一个具有系统生成的名称,请指导如何从DCIM / Camera文件夹中删除该图像。这是我的代码

Open camera 开放式摄像头

 private void openCamera() {
    destination = null;
    PackageManager pm = getPackageManager();
    if (pm.hasSystemFeature(PackageManager.FEATURE_CAMERA)) {
        try {
            String originalfileName = getFilenameOrgImage();
            File root = new File(ConstantData.IMAGE_STORAGE_LOCAL_PATH + File.separator);
            if (!root.exists()) {
                root.mkdirs();
            }
            destination = new File(originalfileName);
            Log.d("destination",destination.getAbsolutePath());
                Uri photoURI = FileProvider.
                        getUriForFile(this, getPackageName() + ".provider", destination);
                Intent takePictureIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
                takePictureIntent.putExtra(MediaStore.EXTRA_OUTPUT, photoURI);
                if (takePictureIntent.resolveActivity(getPackageManager()) != null) {
                    startActivityForResult(takePictureIntent, REQUEST_IMAGE_CAPTURE);
                }

        } catch (Exception e) {
            e.printStackTrace();
            CommonMethods.showToast(this, getResources().getString(R.string.please_try_again));
        }
    } else {
        CommonMethods.showToast(this, getResources().getString(R.string.camera_doesnt_support));
    }
}

onActivityResult onActivityResult

@Override
    protected void onActivityResult(int requestCode, int resultCode, Intent data) {
        super.onActivityResult(requestCode, resultCode, data);
        try {
            if (resultCode == Activity.RESULT_OK) {
                if (requestCode == REQUEST_IMAGE_CAPTURE) {
                    FileInputStream in = new FileInputStream(destination);
                    BitmapFactory.Options options = new BitmapFactory.Options();
                    options.inSampleSize = 10;
                    Log.d("IMAGE",destination.getAbsolutePath());
                    treeDetailsModels.get(imgClickPos).setName(imagename);
                    treeDetailsModels.get(imgClickPos).setImgDestinationPath(destination);

                    View v = viewPager.findViewWithTag("pos" + imgClickPos);
                    ImageView ivBackground = (ImageView) v.findViewById(R.id.ivPhoto);
                    Bitmap bmp = BitmapFactory.decodeStream(in, null, options);
                    ivBackground.setImageBitmap(bmp);
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

Custom location 自定义位置

public static final String IMAGE_STORAGE_LOCAL_PATH = Environment.getExternalStorageDirectory().getPath().toString() + "/ABC";

Added this provide to manifest 添加此提供以显示

<provider
            android:name="android.support.v4.content.FileProvider"
            android:authorities="${applicationId}.provider"
            android:exported="false"
            android:grantUriPermissions="true">
            <meta-data
                android:name="android.support.FILE_PROVIDER_PATHS"
                android:resource="@xml/provider_paths" />
        </provider>

Path 路径

<paths xmlns:android="http://schemas.android.com/apk/res/android">
    <external-path name="external_files" path="ABC/"/>
</paths>

But I have noticed camera is creating two images one stored in ABC folder and another one in DCIM/Camera folder 但是我注意到相机正在创建两个图像,一个图像存储在ABC文件夹中,另一个图像存储在DCIM / Camera文件夹中

Your code is starting a third-party camera app. 您的代码正在启动第三方相机应用。 That app was written by other programmers, and those programmers can do whatever they want. 该应用程序是由其他程序员编写的,这些程序员可以做任何他们想做的事情。 They should not be saving the image twice, but they are welcome to do so. 他们不应两次保存图像,但欢迎这样做。

Please guide how to delete that image from DCIM/Camera folder 请指导如何从DCIM / Camera文件夹中删除该图像

There are ~2 billion Android devices, with hundreds of different pre-installed camera apps and hundreds more camera apps available from the Play Store and elsewhere. 大约有20亿个Android设备,其中有数百种预装的摄像头应用程序,以及Play商店和其他地方提供的数百种摄像头应用程序。 Any of those hundreds of camera apps could be launched by your code. 您的代码可以启动这数百种相机应用程序中的任何一个。 Any of those camera apps can do whatever they want. 这些相机应用程序中的任何一个都可以做他们想做的事。 Some may create extra copies of the photo. 有些可能会创建照片的额外副本。 Some may upload the photo to their servers. 有些人可能将照片上传到他们的服务器。 Some may modify the photo. 有些人可能会修改照片。 Most, hopefully, will do none of these things... but you do not get a vote. 希望大多数人不会做这些事情……但是您没有投票。

So, your choices are: 因此,您的选择是:

  1. Live with the side effects of some camera apps, such as extra copies of the image, or 忍受某些相机应用程序的副作用,例如图像的额外副本,或者

  2. Stop taking photos using ACTION_IMAGE_CAPTURE (either take the photos yourself using the camera hardware, or just stop taking photos entirely) 停止使用ACTION_IMAGE_CAPTURE拍照(或者使用相机硬件自己拍照,或者完全停止拍照)

暂无
暂无

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

相关问题 是否所有带有内置相机的Android手机都使用名为“ DCIM”的文件夹来存储捕获的图像? - Do all Android phones with a built-in camera use a folder called “DCIM” to store captured images? 我想获取要删除图像和视频的android camera gallery文件夹路径的Android DCIM文件夹的路径是什么? - What is the path of the Android DCIM Folder ??i want to get android camera gallery folder path to delete images and videos? 如何从意图打开默认文件应用程序中的 DCIM/Camera 文件夹 - How to open DCIM/Camera folder in default Files app from intent 从相机捕获图像,它存储在sdcard / dcim文件夹中 - Capturing image from Camera, it stores at sdcard/dcim folder 从/内部存储/ DCIM /相机发布图像时出现403错误 - 403 error for Posting images from /Internal storage/DCIM/camera android - 如何通过采样缩略图从 DCIM/CAMERA 中提取图像 - android - how to pull images from DCIM/CAMERA by sampling thumbnails 如何从Android的SD卡中的DCIM / Camera文件夹中检索最后保存的图像 - How to retrieve the last saved image from DCIM/Camera folder in sd card in Android 第二次从相机捕获时无法加载图像 - Not able to load image when captured from Camera second time 在另一活动中无法从自定义相机捕获图像 - Not able to get the image captured from custom camera in another activity 将捕获的图像从相机保存到自定义文件夹反应本地 - Save captured image from camera to custom folder react native
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM