[英]How to get links to all pdf files from removable storage(SD Card) of android in java?
[英]how to fetch files from removable SD card?
这行代码:
ArrayList<File> mySongs = fetchSongs(Environment.getExternalStorageDirectory());
仅从设备的内部存储中获取文件。 并且不读取外部可移动 SD 卡。 我还读到“getExternalStorageDirectory”方法已被弃用,所以有替代方法吗? 还是有任何其他方法可以从外部存储中获取文件? 我也在清单中授予了外部存储权限。
我想到了! 您可以使用以下代码从卡和内部存储中获取一组文件:
String[] allPath = StorageUtil.getStorageDirectories(MainActivity.this);
File phoneStorage = new File(allPath[1]);
File sdCard = new File(allPath[0]);
ArrayList<File> phoneSongs = fetchSongs(phoneStorage);
ArrayList<File> sdCardSongs = fetchSongs(sdCard);
ArrayList<File> mySongs = new ArrayList<>();
mySongs.addAll(phoneSongs);
mySongs.addAll(sdCardSongs);
注意:您必须导入 StorageUtil 类。 在谷歌上搜索它。 我希望它可以帮助某人! 祝你好运。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.