First of all, you want to load file from external storage like sdcard, you'd better use following code:
public File getDataFolder(Context context) {
File dataDir = null;
if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) {
dataDir = new File(Environment.getExternalStorageDirectory(), "myappdata");
if(!dataDir.isDirectory()) {
dataDir.mkdirs();
}
}
if(!dataDir.isDirectory()) {
dataDir = context.getFilesDir();
}
return dataDir;
}
It will return a folder which is named "myappdata" located in your sd-card. After that, if you want to load a image from that folder, you can use following code:
File cacheDir = getDataFolder(this);
File cacheFile = new File(cacheDir, "images.jpeg");
InputStream fileInputStream = new FileInputStream(cacheFile);
BitmapFactory.Options bitmapOptions = new BitmapFactory.Options();
bitmapOptions.inSampleSize = scale;
bitmapOptions.inJustDecodeBounds = false;
Bitmap wallpaperBitmap = BitmapFactory.decodeStream(fileInputStream, null, bitmapOptions);
ImageView imageView = (ImageView)this.findViewById(R.id.preview);
imageView.setImageBitmap(wallpaperBitmap);
If you still have problem with above code, you can check the full example here: