gpt4 book ai didi

android - 从手机的内部存储器+外部SD卡存储器中获取所有图像?

转载 作者:行者123 更新时间:2023-11-29 01:48:16 25 4
gpt4 key购买 nike

我很困惑,我在下面发布的这段代码是否从手机的内部存储器 + 外部 SD 卡存储器中检索所有图像?

如果没有那么如何获取手机内存+外置SD卡内存中的所有图片?

 final String[] columns = { MediaStore.Images.Media.DATA,
MediaStore.Images.Media._ID };
final String orderBy = MediaStore.Images.Media._ID;

//Stores all the images from the gallery in Cursor
Cursor cursor = getContentResolver().query(
MediaStore.Images.Media.EXTERNAL_CONTENT_URI, columns, null,
null, orderBy);

//Total number of images
int count = cursor.getCount();

//Create an array to store path to all the images
String[] arrPath = new String[count];

for (int i = 0; i < count; i++) {
cursor.moveToPosition(i);
int dataColumnIndex = cursor.getColumnIndex(MediaStore.Images.Media.DATA);
//Store the path of the image
arrPath[i]= cursor.getString(dataColumnIndex);
Log.i("PATH", arrPath[i]);
}

最佳答案

试试这个--

public ArrayList<String> getFilePaths()
{


Uri u = MediaStore.Images.Media.EXTERNAL_CONTENT_URI;
String[] projection = {MediaStore.Images.ImageColumns.DATA};
Cursor c = null;
SortedSet<String> dirList = new TreeSet<String>();
ArrayList<String> resultIAV = new ArrayList<String>();

String[] directories = null;
if (u != null)
{
c = managedQuery(u, projection, null, null, null);
}

if ((c != null) && (c.moveToFirst()))
{
do
{
String tempDir = c.getString(0);
tempDir = tempDir.substring(0, tempDir.lastIndexOf("/"));
try{
dirList.add(tempDir);
}
catch(Exception e)
{

}
}
while (c.moveToNext());
directories = new String[dirList.size()];
dirList.toArray(directories);

}

for(int i=0;i<dirList.size();i++)
{
File imageDir = new File(directories[i]);
File[] imageList = imageDir.listFiles();
if(imageList == null)
continue;
for (File imagePath : imageList) {
try {

if(imagePath.isDirectory())
{
imageList = imagePath.listFiles();

}
if ( imagePath.getName().contains(".jpg")|| imagePath.getName().contains(".JPG")
|| imagePath.getName().contains(".jpeg")|| imagePath.getName().contains(".JPEG")
|| imagePath.getName().contains(".png") || imagePath.getName().contains(".PNG"))
{



String path= imagePath.getAbsolutePath();
resultIAV.add(path);

}
}
// }
catch (Exception e) {
e.printStackTrace();
FirebaseCrash.report(e);
}
}
}

return resultIAV;

}

关于android - 从手机的内部存储器+外部SD卡存储器中获取所有图像?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20029650/

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