gpt4 book ai didi

android - 如何查看 "if image gallery is empty"

转载 作者:行者123 更新时间:2023-11-29 00:26:48 24 4
gpt4 key购买 nike

我是 android 的新手,我需要知道如何检查设备图片库是否为空..

方法

File dir = new File(Environment.getExternalStorageDirectory()+ "/images");
File dird = new File("/mnt/sdcard");

File[] files = dir.listFiles();
File[] filesd = dird.listFiles();

if((files==null)||(filesd==null)){
}

谢谢

最佳答案

试试这个

private boolean isImageGalleryEmpty() {

try {
final String[] columns = { MediaStore.Images.Media.DATA, MediaStore.Images.Media._ID };
final String orderBy = MediaStore.Images.Media._ID;
Cursor imagecursor = managedQuery(MediaStore.Images.Media.EXTERNAL_CONTENT_URI, columns, null, null, orderBy);
imagecursor.close();
if (imagecursor.getCount() > 0) {
return false;
} else {
return true;
}
} catch (Exception e) {
}
return true;

}

关于android - 如何查看 "if image gallery is empty",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18757604/

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