做這樣的事情:
imageView = (ImageView)findViewById(R.id.imageView1);
File file = null;
if (isExternalSDCard()) {
file = new File(
Environment
.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES), "photo.jpg");
} else {
file = new File(Environment.getDataDirectory(),
Environment.DIRECTORY_PICTURES);
if (!file.exists()) {
file.mkdirs();
}
file = new File(file, "photo.jpg");
}
if (file != null && file.exists()) {
// First decode with inJustDecodeBounds=true to check dimensions
final BitmapFactory.Options options = new BitmapFactory.Options();
options.inJustDecodeBounds = true;
BitmapFactory.decodeFile(file.getAbsolutePath(), options);
// Decode bitmap with inSampleSize set
options.inJustDecodeBounds = false;
Bitmap bitmap = BitmapFactory.decodeFile(file.getAbsolutePath(),
options);
imageView.setImageBitmap(bitmap);
}
photo.jpg這是你的形象的名字。
在目錄中的所有文件:
File[] filesPhotos = Environment.getExternalStoragePublicDirectory(
Environment.DIRECTORY_PICTURES).listFiles();
^^
我的代碼isExternalSDCard:
private static boolean isExternalSDCard() {
boolean mExternalStorageAvailable = false;
boolean mExternalStorageWriteable = false;
String state = Environment.getExternalStorageState();
if (Environment.MEDIA_MOUNTED.equals(state)) {
// We can read and write the media
mExternalStorageAvailable = mExternalStorageWriteable = true;
} else if (Environment.MEDIA_MOUNTED_READ_ONLY.equals(state)) {
// We can only read the media
mExternalStorageAvailable = true;
mExternalStorageWriteable = false;
} else {
// Something else is wrong. It may be one of many other states, but
// all we need
// to know is we can neither read nor write
mExternalStorageAvailable = mExternalStorageWriteable = false;
}
return mExternalStorageAvailable && mExternalStorageWriteable;
}
我改變相機設置在方便的地方保存照片給我。 我認爲應用程序將其存儲在其設置中,並且每個應用程序的設置都不相同。我意識到他問了一個愚蠢的問題。你已經幫我找到了解決我的問題的方法。 – Ifgeny87
@CommonsWare:我明白你的意思。所以解決方案應該是加載所有文件夾裏面都有圖像,對嗎?你知道該怎麼辦? –