[英]Why does the Camera Intent not returning the image to the ImageView?
What I am trying to achieve is on the map long press it brings up and custom dialog view with 3 buttons, one for photo, one for save and one for cancel.我想要实现的是在地图上长按它会弹出带有 3 个按钮的自定义对话框视图,一个用于照片,一个用于保存,一个用于取消。
So at the moment when tapping on photo the camera intent opens and I can take a photo.所以在点击照片的那一刻,相机意图打开,我可以拍照。 Upon clicking "ok" the intent returns to the custom dialog window but no image is displayed?
单击“确定”后,意图返回到自定义对话框窗口,但没有显示图像?
This is my code I am using at the moment:这是我目前正在使用的代码:
public void onMapLongClick(LatLng point) {
LayoutInflater factory = LayoutInflater.from(MainActivity.this);
final View deleteDialogView = factory.inflate(R.layout.custom_dialog, null);
final AlertDialog deleteDialog = new AlertDialog.Builder(MainActivity.this).create();
deleteDialog.setView(deleteDialogView);
deleteDialogView.findViewById(R.id.btn_photo).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent cameraIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
String f = System.currentTimeMillis()+".jpg"; // Designated name
File file = new File(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DCIM), f);
fileUri = FileProvider.getUriForFile(MainActivity.this, getPackageName() + ".fileprovider", file);
cameraIntent.putExtra(MediaStore.EXTRA_OUTPUT, fileUri);
startActivityForResult(cameraIntent, TAKE_PICTURE);
}
protected void onActivityResult(int requestCode, int resultCode, @Nullable Intent data) {
switch (requestCode) {
case TAKE_PICTURE:
ImageView imgView = findViewById(R.id.a);
imgView.setImageURI(fileUri);
break;
}
}
});
Thanks.谢谢。
Notice that you pass 'fileUri' to the intent, so you also need to get it from the returned intent.请注意,您将 'fileUri' 传递给意图,因此您还需要从返回的意图中获取它。
Try replacing imgView.setImageURI(fileUri);
尝试更换
imgView.setImageURI(fileUri);
with imgView.setImageURI(data.getData());
与
imgView.setImageURI(data.getData());
or或者
Bundle extras = data.getExtras();
Bitmap imageBitmap = (Bitmap) extras.get("data");
which will give you the URI with the image.这将为您提供带有图像的 URI。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.