Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/187.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 如何使用包含图像(*.jpg)的文件夹中的缩略图填充图库?_Android_Android Gallery - Fatal编程技术网

Android 如何使用包含图像(*.jpg)的文件夹中的缩略图填充图库?

Android 如何使用包含图像(*.jpg)的文件夹中的缩略图填充图库?,android,android-gallery,Android,Android Gallery,这是我用来在图库中填充图钉的代码 //-------------------------------------------- final Cursor cursor; final int columnIndex; Gallery g = (Gallery) findViewById(R.id.gallery); // request only the image ID to be returned String[

这是我用来在图库中填充图钉的代码

//--------------------------------------------
        final Cursor cursor;
        final int columnIndex;

        Gallery g = (Gallery) findViewById(R.id.gallery);
        // request only the image ID to be returned
        String[] projection = {MediaStore.Images.Media._ID};
        // Create the cursor pointing to the SDCard

        cursor = managedQuery(
                //uu.build(),
                MediaStore.Images.Media.EXTERNAL_CONTENT_URI,
                projection, 
                MediaStore.Images.Media.DATA + " like ? ",
                new String[] {"%MyIdentityPhotos%"},  
                null);
        cursor.moveToFirst();
        // Get the column index of the image ID
        columnIndex = cursor.getColumnIndexOrThrow(MediaStore.Images.Media._ID);

        g.setAdapter(new BaseAdapter() {
            public int getCount() {
              return cursor.getCount();
            }
            public Object getItem(int position) {

                // Move cursor to current position
                cursor.moveToPosition(position);
                // Get the current value for the requested column
                int imageID = cursor.getInt(columnIndex);
                // obtain the image URI
                Uri uri = Uri.withAppendedPath( MediaStore.Images.Media.EXTERNAL_CONTENT_URI, Integer.toString(imageID) );
                String url = uri.toString();
                // Set the content of the image based on the image URI
                int originalImageId = Integer.parseInt(url.substring(url.lastIndexOf("/") + 1, url.length()));
                return MediaStore.Images.Thumbnails.getThumbnail(getContentResolver(),
                                originalImageId, MediaStore.Images.Thumbnails.MINI_KIND, null);

            }

            public long getItemId(int position) {
              return position;
            }

            public View getView(int position, View convertView, ViewGroup parent) {
                ImageView i = new ImageView(ImViewer.this);
                // Move cursor to current position
                cursor.moveToPosition(position);
                // Get the current value for the requested column
                int imageID = cursor.getInt(columnIndex);
                // obtain the image URI
                Uri uri = Uri.withAppendedPath( MediaStore.Images.Media.EXTERNAL_CONTENT_URI, Integer.toString(imageID) );
                String url = uri.toString();
                // Set the content of the image based on the image URI
                int originalImageId = Integer.parseInt(url.substring(url.lastIndexOf("/") + 1, url.length()));
                Bitmap b = MediaStore.Images.Thumbnails.getThumbnail(getContentResolver(),
                                originalImageId, MediaStore.Images.Thumbnails.MINI_KIND, null);
                i.setImageBitmap(b);

                Display display = getWindowManager().getDefaultDisplay(); 
                int width = display.getWidth();
                //int height = display.getHeight();

                i.setLayoutParams(new Gallery.LayoutParams(width, (int) (width / 0.77) ));
                i.setScaleType(ImageView.ScaleType.CENTER_CROP );
                //i.setBackgroundResource(mGalleryItemBackground);
                return i;
            }

          });
        //--------------------------------------------
这对我来说是不好的,因为这只会检索android内置图库中的图像

我正在寻找的是做同样的事情,但使用一个特定的文件夹

提前感谢

请参见