使用内部存储从android手机上的图库中提取图像 [英] fetching images from gallery on android phones with internal storage

查看:181
本文介绍了使用内部存储从android手机上的图库中提取图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好我正在开发一个Android Gallery应用程序,我从内置库中获取图像并显示它。我使用下面的代码

  String [] projection = {MediaStore.Images.Thumbnails._ID}; 


Cursor cursor = getContentResolver()。query(MediaStore.Images.Thumbnails.INTERNAL_CONTENT_URI,
projection,//返回
的哪些列为null,//返回所有行
null,
null);


int columnIndex = cursor.getColumnIndexOrThrow(MediaStore.Images.Thumbnails._ID);
int size = cursor.getCount();
//如果大小为0,SD卡上没有图像。
if(size == 0)
{
Log.e(size 0,0);





$ b

问题是当我在只有内部存储的电话上运行此代码时(Galaxy Nexus)我得到说大小为零的日志,即使有内置图库中的图像。我该如何解决这个问题。
请帮助。谢谢!

解决方案

要获得图库图片列表,您可以尝试此操作。

  String [] projection = new String [] {
MediaStore.Images.Media._ID,
MediaStore.Images.Media。 BUCKET_DISPLAY_NAME,
MediaStore.Images.Media.DATE_TAKEN
};


Uri imageUri = MediaStore.Images.Media.EXTERNAL_CONTENT_URI;


Cursor cur = getContentResolver()。query(imageUri,
projection,//要返回的列
null,//要返回的行(所有行)
null,//选择参数(无)
null //排序
);

Log.i(图片计数,count =+ cur.getCount());


Hi I am developing an Android Gallery app where I am fetching images from built in gallery and displaying it.I am using the code as below

        String[] projection = {MediaStore.Images.Thumbnails._ID};


   Cursor cursor = getContentResolver().query(MediaStore.Images.Thumbnails.INTERNAL_CONTENT_URI,
                projection, // Which columns to return
                null,       // Return all rows
                null,       
                null);


        int columnIndex = cursor.getColumnIndexOrThrow(MediaStore.Images.Thumbnails._ID);
        int size = cursor.getCount();
        // If size is 0, there are no images on the SD Card.
        if (size == 0) 
        {
            Log.e("size 0","0");
        }

The Problem is when I run this code on Phones having only internal storage (Galaxy Nexus) I am getting Log which says size as Zero even though there are images in built in gallery. How do I resolve this. Please Help.Thanks!

解决方案

To get list of Gallery images you can try this

String[] projection = new String[]{
        MediaStore.Images.Media._ID,
        MediaStore.Images.Media.BUCKET_DISPLAY_NAME,
        MediaStore.Images.Media.DATE_TAKEN
};


Uri imageUri = MediaStore.Images.Media.EXTERNAL_CONTENT_URI;


Cursor cur = getContentResolver().query(imageUri,
        projection, // Which columns to return
        null,       // Which rows to return (all rows)
        null,       // Selection arguments (none)
        null        // Ordering
        );

Log.i("Images Count"," count="+cur.getCount());

这篇关于使用内部存储从android手机上的图库中提取图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆