[英]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: 因此,您的选择是:
Live with the side effects of some camera apps, such as extra copies of the image, or 忍受某些相机应用程序的副作用,例如图像的额外副本,或者
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.