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

标签 android

我是 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/

相关文章:

android - 为什么我的 webview 中的 youtube 只播放声音?

android - 按钮在横向旋转中被切断(Android XML)

android - 如何通过滚动在 ListView 顶部添加项目而不会卡住?

android - 应用程序未从 Play 商店安装在某些设备中

java - 应用程序因空指针异常而崩溃,并且在 android webview 中按下“返回”时出现其他错误

android - 在嵌套的 FragmentTabHost 中切换选项卡后 fragment 不可见

android - 在 GCM 客户端上接收推送通知的问题

android - 从后台恢复 Android 应用程序后,它卡住了

java - Android Studio 中“无法解析符号 R”

安卓初学者 :how to detect specific position on imageview in android