如何从SD卡文件夹中检索图像

时间:2012-02-17 07:26:36

标签: android cursor android-sdcard

我可以在模拟器中检索图像,但是当我在移动设备中尝试此图像时,不会显示图像,下面是我检索图像的代码,当我在模拟器中记录cc.getCount()时它会给出正确的计数但是当在手机上尝试这个时,它总是显示为零(0)。

 String uri = MediaStore.Images.Media.DATA;
        String condition = uri + " like '%/project/images%'";

Cursor cc = this.getContentResolver().query(
                    MediaStore.Images.Media.EXTERNAL_CONTENT_URI, null, condition, null,
                    null);

            if (cc != null) {
                myProgressDialog = new ProgressDialog(PhotosActivity.this);
                myProgressDialog.requestWindowFeature(Window.FEATURE_NO_TITLE);
                myProgressDialog.setMessage("Loading....");
                myProgressDialog.show();

                new Thread() {
                    public void run() {
                        try {
                            cc.moveToFirst();
                            mUrls = new Uri[cc.getCount()];
                            strUrls = new String[cc.getCount()];
                            mNames = new String[cc.getCount()];
                            for (int i = 0; i < cc.getCount(); i++) {
                                cc.moveToPosition(i);
                                mUrls[i] = Uri.parse(cc.getString(1));
                                strUrls[i] = cc.getString(1);
                                mNames[i] = cc.getString(3);
                                Log.e("mNames[i]",mNames[i]+":"+cc.getColumnCount()+ " : " +cc.getString(3));
                            }

                        } catch (Exception e) {
                        }
                        myProgressDialog.dismiss();
                    }
                }.start();
            gridview = (GridView) findViewById(R.id.gridview);
            gridview.setAdapter(new ImageAdapter(this));

            gridview.setOnItemClickListener(new OnItemClickListener() {
                public void onItemClick(AdapterView<?> parent, View v,
                        int position, long id) {


                }
            });

            }

1 个答案:

答案 0 :(得分:0)

Dude转到此链接http://mobile.dzone.com/news/displaying-images-sd-card它提供了很好的例子