gpt4 book ai didi

android - 带和不带 SD 卡的设备的/下载文件夹位置

转载 作者:行者123 更新时间:2023-11-29 14:23:24 24 4
gpt4 key购买 nike

请告诉我 Downloads 文件夹在带 SD 卡和不带 SD 卡的设备上的默认位置是什么。

以及如何检查特定手机是否没有 SD 卡。

最佳答案

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

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

/*
* 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

希望这对您有所帮助。

关于android - 带和不带 SD 卡的设备的/下载文件夹位置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11351840/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com