我正在使用这些代码捕获和存储按钮上的图像点击。捕获和存储照片无法正常工作 - Android
takePhoto.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
destination = new File(Environment
.getExternalStorageDirectory(),
preferences.getSelectedItem().getItemNo() + "_"
+ preferences.getSelectedItem().getChasisNo() + "_up");
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
intent.putExtra(MediaStore.EXTRA_OUTPUT,
Uri.fromFile(destination));
startActivityForResult(intent, TAKE_PHOTO_CODE);
}
});
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == TAKE_PHOTO_CODE && resultCode == RESULT_OK) {
FileInputStream in;
try {
in = new FileInputStream(destination);
BitmapFactory.Options options = new BitmapFactory.Options();
options.inSampleSize = 10;
imgPath = destination.getAbsolutePath();
// Bitmap bmp = BitmapFactory.decodeStream(in, null, options);
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Log.d("Image saved", "Image saved at " + imgPath);
upItem.setUpPhotoURL(String.valueOf(imgPath));
isPhotoAttached = true;
}
}
但是当我捕捉照片并尝试确认它时,应用程序什么都不做。取消和重拍选项可以很好地工作,但确认拍摄的图像不会做任何事情。任何人都可以指出问题出在哪里?
看我的答案在这里它会帮助你http://stackoverflow.com/questions/23606330/how-to-distinguish-whether-the-image-is-coming-from-gallery-or-camera-in-android/23606878#23606878 –
问题是,当我按下确认按钮时resultCode不起作用。我试过Log.d(“Test”,String.valueOf(resultCode));但只有当我按下取消按钮(测试:0)时才会创建日志,而当我试图按下确认按钮时没有任何东西。 –