Question

I use gridView to get the file list. But it can not use filelist.get(position)

I want to get the Thumbnails by using

MediaStore.Images.Thumbnails.getThumbnail(getActivity().getContentResolver(), origId, Images.Thumbnails.MICRO_KIND, null);

But what the origId of image here ???

Is that mean path or name ?

-------------------------------------------------EDIT---------------------------------------

The full code is like the following:

I want to get Thumbnails at getView.

viewTag is the other class , it store the textview.

so viewTag.mFilename.setText(filename); is equal to Textview.setText.

public class LocalFileListAdapter extends BaseAdapter {

        private LayoutInflater mInflater ;
        private ArrayList<FileNode> mFileList ;
        private static final String TAG = "MJPEG Player" ;
        private Context mContext;

        public LocalFileListAdapter(LayoutInflater inflater, ArrayList<FileNode> fileList) {
            mInflater = inflater ;
            mFileList = fileList ;
        }

        public void GridAdapter(Context ctx) {
            // TODO Auto-generated method stub
            mContext = ctx; 
        }

        @Override
        public int getCount() {
            return mFileList == null ? 0 : mFileList.size() ;
        }

        @Override
        public Object getItem(int position) {
            return mFileList == null ? null : mFileList.get(position) ;
        }

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


        @Override
        public View getView(int position, View convertView, ViewGroup parent) {

            ViewTag viewTag ;

            if (convertView == null) {

                convertView = mInflater.inflate(R.layout.filelist_row, null) ;

                TextView fileListName = (TextView) convertView.findViewById(R.id.fileListName);
                fileListName.setSelected(true);

                viewTag = new ViewTag(mContext , (ImageView) convertView.findViewById(R.id.fileListThumbnail), 
                        (ImageView) convertView.findViewById(R.id.select) ,
                        mFileList.get(position) , fileListName , 
                        (TextView) convertView.findViewById(R.id.fileListSize) , 
                        (ImageView) convertView.findViewById(R.id.video_layout) , 
                        (TextView) convertView.findViewById(R.id.fileListTime));

                convertView.setTag(viewTag) ;

            } else {
                viewTag = (ViewTag) convertView.getTag() ;
            }

            viewTag.mFileNode = mFileList.get(position) ;
            String filename = viewTag.mFileNode.mName.substring(viewTag.mFileNode.mName.lastIndexOf("/") + 1) ;

            viewTag.mFilename.setText(filename);

                            MediaStore.Images.Thumbnails.getThumbnail(getActivity().getContentResolver(), Long.parseLong(mFileList.get(position)), Images.Thumbnails.MICRO_KIND, null);

            return convertView ;
        }
    }

How to get the image Id ?

Was it helpful?

Solution 2

That's just an ID that each image has.

From the docs:

The original image for the thumbnail Type: INTEGER (ID from Images table)

http://developer.android.com/reference/android/provider/MediaStore.Images.Thumbnails.html#IMAGE_ID

So, it's neither the path, or the name. It's an internally generated ID for each image in the MediaStore. It's generally the Uri to the image.

OTHER TIPS

You are using following method:

public static Bitmap getThumbnail (ContentResolver cr, long origId, int kind, BitmapFactory.Options options)

Parameters:

cr -> ContentResolver used to dispatch queries to MediaProvider.

origId -> Original image id associated with thumbnail of interest.

kind -> The type of thumbnail to fetch. Should be either MINI_KIND or MICRO_KIND.

options -> this is only used for MINI_KIND when decoding the Bitmap Returns A Bitmap instance. It could be null if the original image associated with origId doesn't exist or memory is not enough.

If you have Image Uri then you will get id from following:

imageUri.getLastPathSegment()

or

String wholeID = DocumentsContract.getDocumentId(imageUri);
String id = wholeID.split(":")[1];
Long origId = Long.parseLong(id);

Now origId you have to pass into getThumbnail()

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top