One*_*rld 7 android android-mediascanner sony-xperia android-5.0-lollipop
重命名应用程序触发的文件之类的更改仅在重新启动Android设备后显示在USB-MTP界面上,或者在MediaScanner上注册新文件之后(请参阅特定路径(文件夹)上的触发媒体扫描程序),如何操作?):
file.renameTo(newFile);
MediaScannerConnection.scanFile(context,
new String[] { newFile.getAbsolutePath() }, null, null);
Run Code Online (Sandbox Code Playgroud)
USB-MTP用于通过USB访问Android设备的存储.例如,使用Windows资源管理器.
但是,使用Android 5.0.2(Build 10.6.A.0.454)下的Sony XPERIA Tablet Z(SGP321)文件夹newFile将成为一个4KB的文件.我不再能够使用Windows资源管理器访问文件夹结构,也无法将文件复制到我的计算机上.即使重启平板电脑!Android 4.4.4的相同设备不显示该行为.似乎只有USB-MTP视图被破坏.Android应用程序访问的文件结构看起来还不错.
问题:这种行为是错误还是我错误地实现了?什么是正确的实施?
到目前为止我为解决这个问题尝试了什么:
scanFile使用目录.MediaScannerConnection#scanFile.重启后,我可以再次使用Windows资源管理器访问该目录./sf/answers/1534265981/ 中建议的这一行不刷新USB-MTP视图,但也不会将目录转换为文件:
context.sendBroadcast(new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE,
Uri.fromFile(newFile.getParentFile()));
Run Code Online (Sandbox Code Playgroud)也许相关:
Ern*_*son 13
我最终在我想要显示的每个目录中创建一个虚拟文本文件,并在文件上使用scanFile.
1)创建目录,但不要"扫描"目录
2)将文件复制到目录
3)在filePath上运行scanFile
MediaScannerConnection.scanFile (_application, new String[] { filePath }, null, null);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2704 次 |
| 最近记录: |