gpt4 book ai didi

android - 在平板电脑的 Android 应用程序中获取外部存储路径

转载 作者:行者123 更新时间:2023-11-29 22:37:56 24 4
gpt4 key购买 nike

我如何在微调器中显示所有外部存储,并以编程方式在 android 应用程序的平板电脑微调器中选择仅访问外部存储

最佳答案

获取外部存储路径 Environment.getExternalStorageState()

final String state = Environment.getExternalStorageState();

if ( Environment.MEDIA_MOUNTED.equals(state) || Environment.MEDIA_MOUNTED_READ_ONLY.equals(state) ) { // we can read the External Storage...
//Retrieve the External Storage:
final File primaryExternalStorage = Environment.getExternalStorageDirectory();

//Retrieve the External Storages from the root directory:
final String externalStorageRootDir;
if ( (externalStorageRootDir = primaryExternalStorage.getParent()) == null ) {
Log.d(TAG, "External Storage: " + primaryExternalStorage + "\n");
}
else {
final File externalStorageRoot = new File( externalStorageRootDir );
final File[] files = externalStorageRoot.listFiles();

for ( final File file: files ) {
if ( file.isDirectory() && file.canRead() && (file.listFiles().length > 0) ) { // it is a directory (not a External drive)...
Log.d(TAG, "External Storage: " + file.getAbsolutePath() + "\n");
}
}
}
}

有关更多信息,请尝试此链接 Find location of a removable SD card

关于android - 在平板电脑的 Android 应用程序中获取外部存储路径,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59320000/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com