Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7980951
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T10:13:41+00:00 2026-06-04T10:13:41+00:00

I am deleting an image file from my application. I was doing new File(filename).delete

  • 0

I am deleting an image file from my application. I was doing

new  File(filename).delete ();

This was actually deleting the file. But the image was still visible in the gallery.

On search i found that we should use

getContentResolver().delete(Uri.fromFile(file), null,null); to delete

But here i am getting the exception:

Unknown file URL. java.lang.IllegalArgumentException: Unknown URL
file:///mnt/sdcard/DCIM/Camera/IMG_20120523_122612.jpg

When i see with any file browser, this particular image is present. Please help me to fix this issue. Is there any other way to update gallery when image is physically deleted

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T10:13:44+00:00Added an answer on June 4, 2026 at 10:13 am

    Use the code below, it may help you.

    File fdelete = new File(file_dj_path);
    if (fdelete.exists()) {
        if (fdelete.delete()) {
            System.out.println("file Deleted :" + file_dj_path);
        } else {
            System.out.println("file not Deleted :" + file_dj_path);
        }
    }
    

    to refresh gallery after deleting image use below code for send Broadcast

    (for < KITKAT API 14)

     sendBroadcast(new Intent(Intent.ACTION_MEDIA_MOUNTED,
     Uri.parse("file://" +  Environment.getExternalStorageDirectory())));
    

    For >= KITKAT API 14 use below code

    MediaScannerConnection.scanFile(this, new String[] { Environment.getExternalStorageDirectory().toString() }, null, new MediaScannerConnection.OnScanCompletedListener() {
                /*
                 *   (non-Javadoc)
                 * @see android.media.MediaScannerConnection.OnScanCompletedListener#onScanCompleted(java.lang.String, android.net.Uri)
                 */
                public void onScanCompleted(String path, Uri uri) 
                  {
                      Log.i("ExternalStorage", "Scanned " + path + ":");
                      Log.i("ExternalStorage", "-> uri=" + uri);
                  }
                });
    

    Because:

    ACTION_MEDIA_MOUNTED
    

    is deprecated in KITKAT(API 14).


    EDITED 04-09-2015

    its working fine check below code

    public void deleteImage() {
            String file_dj_path = Environment.getExternalStorageDirectory() + "/ECP_Screenshots/abc.jpg";
            File fdelete = new File(file_dj_path);
            if (fdelete.exists()) {
                if (fdelete.delete()) {
                    Log.e("-->", "file Deleted :" + file_dj_path);
                    callBroadCast();
                } else {
                    Log.e("-->", "file not Deleted :" + file_dj_path);
                }
            }
        }
    
        public void callBroadCast() {
            if (Build.VERSION.SDK_INT >= 14) {
                Log.e("-->", " >= 14");
                MediaScannerConnection.scanFile(this, new String[]{Environment.getExternalStorageDirectory().toString()}, null, new MediaScannerConnection.OnScanCompletedListener() {
                    /*
                     *   (non-Javadoc)
                     * @see android.media.MediaScannerConnection.OnScanCompletedListener#onScanCompleted(java.lang.String, android.net.Uri)
                     */
                    public void onScanCompleted(String path, Uri uri) {
                        Log.e("ExternalStorage", "Scanned " + path + ":");
                        Log.e("ExternalStorage", "-> uri=" + uri);
                    }
                });
            } else {
                Log.e("-->", " < 14");
                sendBroadcast(new Intent(Intent.ACTION_MEDIA_MOUNTED,
                        Uri.parse("file://" + Environment.getExternalStorageDirectory())));
            }
        }
    

    below is logs

    09-04 14:27:11.085    8290-8290/com.example.sampleforwear E/-->﹕ file Deleted :/storage/emulated/0/ECP_Screenshots/abc.jpg
    09-04 14:27:11.085    8290-8290/com.example.sampleforwear E/-->﹕ >= 14
    09-04 14:27:11.152    8290-8290/com.example.sampleforwear E/﹕ appName=com.example.sampleforwear, acAppName=/system/bin/surfaceflinger
    09-04 14:27:11.152    8290-8290/com.example.sampleforwear E/﹕ 0
    09-04 14:27:15.249    8290-8302/com.example.sampleforwear E/ExternalStorage﹕ Scanned /storage/emulated/0:
    09-04 14:27:15.249    8290-8302/com.example.sampleforwear E/ExternalStorage﹕ -> uri=content://media/external/file/2416
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

My application is deleting a file from the ftp in about 15s no matter
When i am deleting a SMS message from android system, with this code: context.getContentResolver().delete(
What i want to do: delete an image file from the private internal storage
I am Unable To Delete Image File From My Server Path It Gaves Error
I'm deleting a file as such File fileToDelete = new File(filepath); Boolean fileDeleted =
I'm unable to delete my file, i have looked here but can't find the
I'm trying to load an image store in locally and then delete original file.
I am developing an image processing application in ios5. In this application I want
When deleting a record from the database, occasionally I will run into a reference
Locally deleting a file followed by svn update restores the local copy of that

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.