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 6577649
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T15:39:49+00:00 2026-05-25T15:39:49+00:00

Things should be simple, but as most of the time, in Android, aren’t. I

  • 0

Things should be simple, but as most of the time, in Android, aren’t. I need to format the SD card if the user selects the option in my app. Don’t ask me why I need to do this if it’s already in the OS… not practical but it’s a requirement that I need to implement. As you may know, there is an option in Settings \ Storage \ Erase SD Card. I took a look at the froyo source code and it’s something like:

final IMountService service =
         IMountService.Stub.asInterface(ServiceManager.getService("mount"));
        if (service != null) {
            new Thread() {
                public void run() {
                try {
                        service.formatVolume(Environment.getExternalStorageDirectory().toString());
                    } catch (Exception e) {
                        // Intentionally blank - there's nothing we can do here
                    Log.w("MediaFormat", "Unable to invoke IMountService.formatMedia()");
                    }
                }
            }.start();
        } else {
            Log.w("MediaFormat", "Unable to locate IMountService");
        }

It uses android.os.storage.IMountService and android.os.ServiceManager and I don’t seem to have access to it. So, as I see it I could recursively search every file and delete it but that would be “not on my taste”… or I could start the screen from Erase SD card to the user.

Any help is more then welcome, as I am stuck.

  • 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-05-25T15:39:50+00:00Added an answer on May 25, 2026 at 3:39 pm

    I can’t find again the question here on SO, but It had a working solution. So all credit goes to that guy 😉

    public void wipeMemoryCard() {
            File deleteMatchingFile = new File(Environment
                    .getExternalStorageDirectory().toString());
            try {
                File[] filenames = deleteMatchingFile.listFiles();
                if (filenames != null && filenames.length > 0) {
                    for (File tempFile : filenames) {
                        if (tempFile.isDirectory()) {
                            wipeDirectory(tempFile.toString());
                            tempFile.delete();
                        } else {
                            tempFile.delete();
                        }
                    }
                } else {
                    deleteMatchingFile.delete();
                }
            } catch (Exception e) {
                Utils.log(e.getMessage());
            }
        }
    
        private static void wipeDirectory(String name) {
            File directoryFile = new File(name);
            File[] filenames = directoryFile.listFiles();
            if (filenames != null && filenames.length > 0) {
                for (File tempFile : filenames) {
                    if (tempFile.isDirectory()) {
                        wipeDirectory(tempFile.toString());
                        tempFile.delete();
                    } else {
                        tempFile.delete();
                    }
                }
            } else {
                directoryFile.delete();
            }
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This should be a really really simple thing, but for some reason it is
What things should be kept most in mind when writing cross-platform applications in C?
I'm a newcomer to Python but I understand that things should not be done
I need to collect usage information on my on-demand application. This should include things
There are many things that all programmers should know, but I am particularly interested
I have what should be a simple thing but my unfamiliarity with .NET and
I'm still trying to wrap my head around how things should be done in
What are the best practices for dealing with Things that should be hashed. i.e.
I'm just starting with Mercurial and one of the things that I should do
The loop below is callign a proc that does various 'things' If it should

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.