我试图将照片保存在Android的一个子文件夹。这里有一点我code:
I'm trying to save pictures in a subfolder in Android. Here's a bit of my code:
File path = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM);
path = new File(path, "SubDirName");
path.mkdirs();
(我试过 getExternalStorageDirectory
而不是 getExternalStoragePublicDirectory
和图片文件夹,而不是DCIM)
(I've tried getExternalStorageDirectory
instead of getExternalStoragePublicDirectory
and the Pictures folder instead of DCIM.)
的事情是,所有子文件夹添加,包括它的内容,不要在Windows资源管理器显示时,该设备通过USB连接。它显示在Android文件管理器,但。
The thing is that any subfolder I add, including its contents, don't show up in Windows Explorer when the device is connected via USB. It does show in the Android File Manager, though.
我已经试过广播在新目录的父 ACTION_MEDIA_MOUNTED
意图。它没有工作。
I've tried broadcasting the ACTION_MEDIA_MOUNTED
intent on the new directory's parent. It didn't work.
如果我在Windows中添加一个文件,它显示了在Android上。如果我通过文件管理器在Android上添加一个文件,它显示在Windows中。如果以编程方式添加的文件,它显示了在Android文件管理器,但不是在Windows资源管理器。我的需要的从Windows得到它,我不希望最终用户必须手动创建该文件夹。
If I add a file in Windows, it shows up on Android. If I add a file on Android via the File Manager, it shows up in Windows. If I add the file programmatically, it shows up on the Android File Manager but not in Windows Explorer. And I need to get it from Windows and I don't want the final user to have to create the folder manually.
我是什么做错了吗?
连题目好像是老了。我面临着同样的问题,并重新启动或者Android设备或PC不是为用户实际的解决方案。 :)这个问题是通过使用MTP协议(我讨厌这个协议)的。什么,你所要做的就是开始的可用文件的重新扫描,并且可以使用这样做的 MediaScannerConnection
类:
Even the topic seems to be old. I faced the same issue and rebooting either the Android device or the PC is not practical solution for users. :) This issue is through the use of the MTP protocol (I hate this protocol). What you have to do is to initiate a rescan of the available files and you can do this using the MediaScannerConnection
class:
// snippet taken from question
File path = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM);
path = new File(path, "SubDirName");
path.mkdirs();
// 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(this, new String[] {path.toString()}, null, null);
上一篇:如何确定播出意向的发送者意向
下一篇:通过滚动事件另一种观点观点、事件