int
デバイスのギャラリーにある画像の数の値を取得しようとしています。これを後でループして画像を取得するために使用します。
private class ClickListener implements View.OnClickListener {
@Override
public void onClick(View v) {
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(intent, CAMERA);
}
}
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == CAMERA) {
if (resultCode == Activity.RESULT_OK) {
Bundle extras = data.getExtras();
bmp = (Bitmap) extras.get("data");
MediaStore.Images.Media.insertImage(getContentResolver(), bmp,
"picture", "a picture");
Log.v("HEY", "Your image should be in the gallery now");
Log.v("IMAGES", "Number of Images: " + getImageCount());
} else if (resultCode == Activity.RESULT_CANCELED) {
Log.v("CANCELED", "The user has canceled the activity");
}
}
}
public int getImageCount() {
File dir = new File(Environment.getExternalStorageDirectory() + "/Camera");
File[] files = dir.listFiles();
int numberOfImages = files.length;
return numberOfImages;
}
ただし、logcat はこれを投稿しています
06-19 18:24:41.380: V/HEY(5367): Your image should be in the gallery now
06-19 18:24:41.380: V/IMAGES(5367): Number of Images: 1
そのため、実際の画像数が現在 14 であるのに、画像が 1 枚あることがわかります。何か単純なものが欠けているに違いありませんが、見えません。どんな助けでも大歓迎です。