我正在尝试从相机或图库中拍摄图像,这是我正在运行的代码,但它给了我 String s;
Format formatter;
Date date = new Date();
// 01/09/02
formatter = new SimpleDateFormat("dd/MM/yyyy");
s = formatter.format(date);
System.out.println(s);
的错误:
startActivityForResult
所以,这是我的代码,但我不知道是什么问题,我无法理解。 有人可以帮帮我吗?
答案 0 :(得分:1)
我可以想到两个案例
如果您在活动中覆盖onActivityResult()
,请务必在活动中致电super.onActivityResult()
如果您的片段是嵌套片段,则需要手动将结果从父片段转发到嵌套片段
答案 1 :(得分:1)
此代码用于浏览
case R.id.take_pic:
startActivityForResult(new Intent(
android.provider.MediaStore.ACTION_IMAGE_CAPTURE),
TAKE_REQUEST);
break;
case R.id.browse_pic:
Intent intent = new Intent();
intent.setType("image/*");
intent.setAction(Intent.ACTION_GET_CONTENT);
intent.addCategory(Intent.CATEGORY_OPENABLE);
startActivityForResult(intent, SELECT_REQUEST);
break;
onActivity结果
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == TAKE_REQUEST && resultCode == Activity.RESULT_OK) {
pic = (Bitmap) data.getExtras().get("data");
imageView.setImageBitmap(pic);
}
if (requestCode == SELECT_REQUEST && resultCode == Activity.RESULT_OK) {
try {
InputStream stream = getActivity().getContentResolver()
.openInputStream(data.getData());
pic = BitmapFactory.decodeStream(stream);
stream.close();
imageView.setImageBitmap(pic);
} catch (Exception e) {
e.printStackTrace();
}
}
}