Java tutorial
//package com.java2s; //License from project: Apache License import android.content.Context; import android.graphics.Bitmap; import android.graphics.BitmapFactory; import android.net.Uri; import android.util.Log; import java.io.File; import java.io.FileNotFoundException; import java.io.InputStream; public class Main { public static Bitmap getSDImg(Context context, String imagePath) { if (context == null || imagePath == null) { return null; } Bitmap bitmap = null; InputStream is = null; try { File file = new File(imagePath); if (!file.exists()) { return null; } if (file.isDirectory()) { return null; } imagePath = "file://" + imagePath; Log.i("info", imagePath); is = context.getContentResolver().openInputStream(Uri.parse(imagePath)); bitmap = BitmapFactory.decodeStream(is); } catch (FileNotFoundException e) { } catch (OutOfMemoryError e) { } finally { if (is != null) { try { is.close(); } catch (Exception e) { } } } return bitmap; } }