3

我是 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)){
    }

谢谢

4

2 回答 2

1

试试这个方法

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;

    }
于 2013-09-12T07:15:59.887 回答
1

问题解决了

    String[] projection = {MediaStore.Images.Media._ID};
     Cursor cursor = getContentResolver().query(MediaStore.Images.Media.EXTERNAL_CONTENT_URI,
            projection, null,null,null);
    int columnIndex = ursor.getColumnIndexOrThrow(MediaStore.Images.Media._ID);
    int size = cursor.getCount();
    // If size is 0, there are no images on the SD Card.
    if (size == 0) {

    } else {


    }

谢谢大家。。

于 2013-09-13T02:37:45.297 回答