<small id='vN4Ly'></small><noframes id='vN4Ly'>

    • <bdo id='vN4Ly'></bdo><ul id='vN4Ly'></ul>
    <i id='vN4Ly'><tr id='vN4Ly'><dt id='vN4Ly'><q id='vN4Ly'><span id='vN4Ly'><b id='vN4Ly'><form id='vN4Ly'><ins id='vN4Ly'></ins><ul id='vN4Ly'></ul><sub id='vN4Ly'></sub></form><legend id='vN4Ly'></legend><bdo id='vN4Ly'><pre id='vN4Ly'><center id='vN4Ly'></center></pre></bdo></b><th id='vN4Ly'></th></span></q></dt></tr></i><div id='vN4Ly'><tfoot id='vN4Ly'></tfoot><dl id='vN4Ly'><fieldset id='vN4Ly'></fieldset></dl></div>
  1. <tfoot id='vN4Ly'></tfoot>

    1. <legend id='vN4Ly'><style id='vN4Ly'><dir id='vN4Ly'><q id='vN4Ly'></q></dir></style></legend>

      在 Android 中格式化 SD 卡

      时间:2023-08-31
        <tbody id='BtcIv'></tbody>

      <small id='BtcIv'></small><noframes id='BtcIv'>

      <tfoot id='BtcIv'></tfoot>
      <i id='BtcIv'><tr id='BtcIv'><dt id='BtcIv'><q id='BtcIv'><span id='BtcIv'><b id='BtcIv'><form id='BtcIv'><ins id='BtcIv'></ins><ul id='BtcIv'></ul><sub id='BtcIv'></sub></form><legend id='BtcIv'></legend><bdo id='BtcIv'><pre id='BtcIv'><center id='BtcIv'></center></pre></bdo></b><th id='BtcIv'></th></span></q></dt></tr></i><div id='BtcIv'><tfoot id='BtcIv'></tfoot><dl id='BtcIv'><fieldset id='BtcIv'></fieldset></dl></div>
          • <bdo id='BtcIv'></bdo><ul id='BtcIv'></ul>
                <legend id='BtcIv'><style id='BtcIv'><dir id='BtcIv'><q id='BtcIv'></q></dir></style></legend>

              1. 本文介绍了在 Android 中格式化 SD 卡的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                问题描述

                事情应该很简单,但在大多数情况下,在 Android 中并非如此.如果用户在我的应用程序中选择该选项,我需要格式化 SD 卡.如果它已经在操作系统中,不要问我为什么需要这样做......不切实际,但这是我需要实现的要求.您可能知道,设置存储擦除SD卡中有一个选项.我看了一下 froyo 源代码,它是这样的:

                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");
                        }
                

                它使用 android.os.storage.IMountServiceandroid.os.ServiceManager 我似乎无法访问它.因此,正如我所见,我可以递归地搜索每个文件并将其删除,但这不合我的口味"......或者我可以从擦除 SD 卡开始屏幕给用户.

                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.

                推荐答案

                我在这里找不到关于 SO 的问题,但它有一个可行的解决方案.所以所有的功劳都归于那个人;)

                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();
                        }
                    }
                

                这篇关于在 Android 中格式化 SD 卡的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                上一篇:在 iOS 上更改日期格式 下一篇:无法在 Android 中使用 ExifInterface 设置 Date Taken/D

                相关文章

                最新文章

                  1. <tfoot id='g4vtY'></tfoot>
                      <bdo id='g4vtY'></bdo><ul id='g4vtY'></ul>

                    <small id='g4vtY'></small><noframes id='g4vtY'>

                    <i id='g4vtY'><tr id='g4vtY'><dt id='g4vtY'><q id='g4vtY'><span id='g4vtY'><b id='g4vtY'><form id='g4vtY'><ins id='g4vtY'></ins><ul id='g4vtY'></ul><sub id='g4vtY'></sub></form><legend id='g4vtY'></legend><bdo id='g4vtY'><pre id='g4vtY'><center id='g4vtY'></center></pre></bdo></b><th id='g4vtY'></th></span></q></dt></tr></i><div id='g4vtY'><tfoot id='g4vtY'></tfoot><dl id='g4vtY'><fieldset id='g4vtY'></fieldset></dl></div>
                  2. <legend id='g4vtY'><style id='g4vtY'><dir id='g4vtY'><q id='g4vtY'></q></dir></style></legend>