Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
//License from project: Open Source License 

import android.app.Activity;

import android.database.Cursor;

import android.net.Uri;
import android.provider.MediaStore;
import android.provider.MediaStore.Images.Thumbnails;

public class Main {
    public static Uri getBitmapFromImageId(Activity activity, int imageId) {
        String[] tinyImgPprojection = { MediaStore.Images.Thumbnails._ID };
        Cursor tinyCursor = Thumbnails.queryMiniThumbnail(activity.getContentResolver(), imageId,
                Thumbnails.MINI_KIND, tinyImgPprojection);
        if (tinyCursor.getCount() != 0) {
            tinyCursor.moveToFirst();
            int tinyImgId = tinyCursor.getInt(tinyCursor.getColumnIndexOrThrow(MediaStore.Images.Thumbnails._ID));
            tinyCursor.close();
            return Uri.withAppendedPath(MediaStore.Images.Thumbnails.EXTERNAL_CONTENT_URI,
                    String.valueOf(tinyImgId));
        } else {
            tinyCursor.close();
            return null;
        }
    }
}