中/下载文件夹位置使用和不使用SD卡的设备 [英] Location of /Downloads folder for devices with and without SD card

查看:85
本文介绍了中/下载文件夹位置使用和不使用SD卡的设备的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请让我知道什么是下载文件夹中有和没有SD卡设备的默认位置。

Please let me know what are default locations for Downloads folder on devices with and without SD card.

和我怎么能检查是否特定的手机没有SD卡。

And how can I check if particular phone doesn't have SD card.

推荐答案

要检查,看看设备是否具有SD卡,可以使用: Environment.getExternalStorageState()如果你没有SD卡,可以使用: Environment.getDataDirectory()

To check and see if a device has an SD card, you use: Environment.getExternalStorageState() if you don't have an SD card, you use: Environment.getDataDirectory()

从本质上讲,如果没有SD卡,您可以在本地创建自己的设备上的目录。我列出了一些code,可以帮助:

Essentially, if there is no SD card, you can create your own directory on the device locally. I've listed some code that might help:

/*
             * This sections checks the phone to see if there is a SD card. if
             * there is an SD card, a directory is created on the SD card to
             * store the test log results. If there is not a SD card, then the
             * directory is created on the phones internal hard drive
             */
                    //if there is no SD card, create new directory objects to make directory on device
            if (Environment.getExternalStorageState() == null) {
                            //create new file directory object
                directory = new File(Environment.getDataDirectory()
                        + "/RobotiumTestLog/");
                photoDirectory = new File(Environment.getDataDirectory()
                        + "/Robotium-Screenshots/");
                /*
                 * this checks to see if there are any previous test photo files
                 * if there are any photos, they are deleted for the sake of
                 * memory
                 */
                if (photoDirectory.exists()) {
                    File[] dirFiles = photoDirectory.listFiles();
                    if (dirFiles.length != 0) {
                        for (int ii = 0; ii <= dirFiles.length; ii++) {
                            dirFiles[ii].delete();
                        }
                    }
                }
                // if no directory exists, create new directory
                if (!directory.exists()) {
                    directory.mkdir();
                }

                // if phone DOES have sd card
            } else if (Environment.getExternalStorageState() != null) {
                // search for directory on SD card
                directory = new File(Environment.getExternalStorageDirectory()
                        + "/RobotiumTestLog/");
                photoDirectory = new File(
                        Environment.getExternalStorageDirectory()
                                + "/Robotium-Screenshots/");
                if (photoDirectory.exists()) {
                    File[] dirFiles = photoDirectory.listFiles();
                    if (dirFiles.length > 0) {
                        for (int ii = 0; ii < dirFiles.length; ii++) {
                            dirFiles[ii].delete();
                        }
                        dirFiles = null;
                    }
                }
                // if no directory exists, create new directory to store test
                // results
                if (!directory.exists()) {
                    directory.mkdir();
                }
            }// end of SD card checking

希望这有助于。

Hope this helps.

这篇关于中/下载文件夹位置使用和不使用SD卡的设备的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆