these files are not visible in the files and folders that can be accessed via USB
一旦MediaScannerConnection将它们编入索引,它们就会成为.您可以在MediaScannerConnection上使用scanFile()来加快速度.
另请注意,用户可能需要在其MTP客户端(例如,Windows资源管理器)中使用“刷新”或“重新加载”选项来查看文件,甚至可能需要拔出/重新插入设备,因为某些MTP客户端会缓存目录列表.
When I check the appDir it has the path /storage/emulated/0/MyApp/. Everything works fine, except that this folder is not visible via USB.
这将是外部存储根目录下的MyApp /目录,至少对于手机而言.对于具有辅助用户的平板电脑,当用户登录平板电脑时,用户可以看到MyApp /目录.存储/模拟/ 0 /路径是动态的,用于路由应用程序的代码以写入正确的位置.
另外,请尽量不要使用getExternalStorageDirectory()并使用户的外部存储空间混乱.如果这些是用户应该操作的文件,请尝试将它们放在Environment.getExternalStoragePublicDirectory()指定的位置.