0

I am trying to delete an image from the Camera folder of phone (hardware) via app (programmatically). the code I am using is as follows

File file = new File(Environment.GetExternalStoragePublicDirectory(Environment.DirectoryDcim), "/Camera");

var images = file.ListFiles();

var file2 = new File(file.AbsolutePath, "/myImage.jpg");

bool deleted = file2.Delete();

The AndroidManifest.xml has only following permissions

<uses-sdk android:minSdkVersion="16" />
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />

The path file2 showing is

"{/storage/emulated/0/DCIM/Camera/myImage.jpg}"

still it is not deleting the image from the mobile. However, when the above code executes first time then it shows that the image has been deleted i.e. deleted variable is true but when I check myImage.jpg in my mobile its still there.

In subsequent execution of the code, it doesn't get myImage.jpg in images variable but file present in the mobile Camera folder.

There is already an answer in java but I am using C# Xamarin.

Karan
  • 752
  • 2
  • 13
  • 34

1 Answers1

-1

It appears that if you have Samsung Cloud services automatically backing up your data then it still shows the deleted images in phones Camera folder until unless you do not delete that image from phone itself manually.

The following code is working

File file = new File(Environment.GetExternalStoragePublicDirectory(Environment.DirectoryDcim), "/Camera");

var images = file.ListFiles();

var file2 = new File(file.AbsolutePath, "/myImage.jpg");

bool deleted = file2.Delete();

Just make sure that any other app is not backing up your data while deleting.

Karan
  • 752
  • 2
  • 13
  • 34