Android 带SD卡和不带SD卡的设备的/下载文件夹的位置
请让我知道在有SD卡和没有SD卡的设备上,Android 带SD卡和不带SD卡的设备的/下载文件夹的位置,android,Android,请让我知道在有SD卡和没有SD卡的设备上,下载文件夹的默认位置 如何检查特定手机是否没有SD卡。要检查设备是否有SD卡,请使用:环境。getExternalStorageState()如果没有SD卡,请使用:环境。getDataDirectory() 基本上,如果没有SD卡,您可以在本地设备上创建自己的目录。我列出了一些可能有用的代码: /* * This sections checks the phone to see if there is a SD card. i
下载
文件夹的默认位置
如何检查特定手机是否没有SD卡。要检查设备是否有SD卡,请使用:
环境。getExternalStorageState()
如果没有SD卡,请使用:环境。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
/*
*本节检查手机是否有SD卡。如果
*有一个SD卡,在SD卡上创建一个目录
*存储测试日志结果。如果没有SD卡,则
*目录是在手机内部硬盘上创建的
*/
//若并没有SD卡,创建新的目录对象以在设备上创建目录
if(Environment.getExternalStorageState()==null){
//创建新的文件目录对象
目录=新文件(Environment.getDataDirectory()
+“/RobotiumTestLog/”;
photoDirectory=新文件(Environment.getDataDirectory()
+“/Robotium屏幕截图/”;
/*
*这将检查是否存在任何以前的测试照片文件
*如果有任何照片,它们将被删除,以便
*记忆
*/
if(photoDirectory.exists()){
File[]dirFiles=photoDirectory.listFiles();
如果(dirFiles.length!=0){
对于(int ii=0;ii 0){
对于(int ii=0;ii
希望这有帮助。我不知道内部下载位置 要以编程方式获取外部下载位置,请使用:
Environment.getExternalStorageDirectory()+"/Downloads/"
或者至少,这就是我的HTC EVO 4G上的内容
对于我的应用程序,我开发了一个简单的类来检测SD卡的当前状态,简化为人类可以理解的术语
Environment.getExternalStorageState()
并将其与环境
类下定义的各种默认状态进行比较。重要的是环境。删除的媒体
和环境。共享的媒体
。第一个(我相信)告诉您是否有任何外部存储,第二个告诉您是否已装入
注意:在比较状态时,请使用.equals,因为它们是字符串,而不是像Android中的大多数状态对象那样的整数。有时下载文件夹的名称可能会根据您应该使用的设备而改变,例如
Environment.getExternalStorageDirectory()+“/”+Environment.DIRECTORY\u DOWNLOADS+“/”
获取下载文件夹的路径