编程更新SD卡的文件不会更新Windows资源管理器 [英] SD card files updated programmatically are not updated in windows explorer

查看:87
本文介绍了编程更新SD卡的文件不会更新Windows资源管理器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的应用程序的SD卡(删除或更新文件)的文件操作。
但是,当我通过USB将设备连接到Windows 7,我看不出有什么变化。不过,我可以确认文件,其中更新或者与亚行的shell删除。

My application does file operations on the SD card (delete or update file). But when I connect the device to Windows 7 through USB, I do not see any changes. However I can confirm files where updated or deleted with adb shell.

我使用华硕Eee Pad采用Android 3.0。

I use an ASUS eee Pad with Android 3.0.

这似乎运行Android 3.0有不同的方式来提供访问文件系统(MTP,而不是USB大容量存储)设备。我也了解我们如何使用 MediaScannerConnection.scanFile 添加一个新的文件时刷新Windows文件浏览器中的内容。

It seems devices running Android 3.0 have a different way to provide access to the file system (MTP instead of USB Mass Storage). I also read about how we can use MediaScannerConnection.scanFile to refresh the content of Windows File Explorer when adding a new file.

但如何触发刷新时,文件被删除或更新?

But how to trigger a refresh when files are deleted or updated?

我试过 MediaScannerConnection.scanFile 上已删除的文件,但它仅创建大小为0的输入 MediaScannerConnection.scanFile 对整个文件夹也不起作用。

I tried MediaScannerConnection.scanFile on the deleted file but it only creates an entry with size 0. MediaScannerConnection.scanFile on the whole folder does not work either.

感谢您的帮助。

-G。

推荐答案

所以,在之前的评论中提及。现在我已经找到了最好的

So, as mentioned in the comment before. For now the best I've found is

sendBroadcast(new Intent(Intent.ACTION_MEDIA_MOUNTED,
Uri.parse("file://" + Environment.getExternalStorageDirectory())));

在一个文件被删除或更新似乎工作。

After a file was deleted or updated seems to work.

然而,该装置必须通过USB断开。否则,你需要拔下并重新插入该设备看到的变化。

However, the device must be disconnected from USB. Otherwise you need to unplug and replug the device to see the changes.

请注意:
在某些设备上,这可能对当前活动触发onResume事件。

NOTE: On some devices this may trigger a onResume event on the current activity.

这篇关于编程更新SD卡的文件不会更新Windows资源管理器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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