Android:动态制作的目录对用户不起作用

时间:2012-08-27 18:49:51

标签: android directory xoom mkdirs

我尝试使用mkdirs()动态创建目录,并且它成功创建了目录并将文件复制到创建的目录中。可以在平板电脑(xoom)中看到新目录,但是当我连接到我的PC复制某些文件时,目录不会出现。

我能做什么?

EDT: 这就是我所做的:

File dirs = new File(Environment.getExternalStorageDirectory()+"/MyDir/");
    dirs.mkdirs();

有什么问题?

EDT2: 我已尝试过这个帖子中的所有内容(http://stackoverflow.com/questions/6218572/creating-a-folder-programmatically-on-a-xoom)并且无效。建议?

PS:我找到了一个重新扫描de sdcard的应用程序。如果我创建目录并使用此应用程序,它将完美地工作。有谁知道如何重新扫描SD卡?

3 个答案:

答案 0 :(得分:1)

我已经通过执行上面的答案中推荐的以下行以及https://stackoverflow.com/a/8606529/2482894

解决了这个问题
sendBroadcast(new Intent(Intent.ACTION_MEDIA_MOUNTED,
Uri.parse("file://" + Environment.getExternalStorageDirectory())));

答案 1 :(得分:1)

相当旧的帖子,但想添加不需要添加URI的答案。

// initiate media scan and put the new things into the path array to
// make the scanner aware of the location and the files you want to see
MediaScannerConnection.scanFile(context, new String[] {filePath}, null, null);

答案 2 :(得分:0)

有些内存和SD卡的平板电脑(我认为包含xoom)有不同的存储方式。 getExternalStorage指向文件夹/ mnt / SDCard,但这是内部存储器,要到达SDCard,路径是/ mnt / SDCard / SDCard(我知道很奇怪)。

因此,您需要在平板电脑上查看SDCard的真实装载,并查看Environment.getExternalStorageDirectory()的值,否则您将无法保存在SDCard上,而是保存在平板电脑文件系统中。

编辑:这可能是xoom的媒体驱动程序出现问题,它应该在用户安装到PC上时扫描SD卡。

要重新扫描SD卡,您可以卸载并装载,使用Gallery应用程序刷新SD卡或以编程方式调用 sendBroadcast(new Intent(Intent.ACTION_MEDIA_MOUNTED, Uri.parse("file://" + Environment.getExternalStorageDirectory().getAbsolutePath())));

相关问题