I have a simple Android application. I want to start the camera by creating an intent and then take photo and set the photo in an imageview which is dynamically added to the relative layout. The relative layout is static inside a layout.
I have been trying the following code, but it doesn't work. If I debug I can see the image taken from the camerai in the imageview.
public void setImage(Uri imgUri){
try{
DisplayMetrics metrics = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(metrics);
int width = metrics.widthPixels;
int height = metrics.heightPixels;
ImageView imgView = new ImageView(this);
imgView.setImageURI(imgUri);
imgView.setBackgroundColor(Color.BLACK);
RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(width,height);
params.addRule(RelativeLayout.CENTER_HORIZONTAL);
imgView.setLayoutParams(params);
imgHolder.addView(imgView);
Button btnTest = new Button(this);
btnTest.setText("blabla");;
imgHolder.addView(btnTest);
Toast.makeText(getApplicationContext(),"Picture will be shown now", Toast.LENGTH_LONG).show();
}catch(Exception e){
Toast.makeText(getApplicationContext(),e.toString(), Toast.LENGTH_LONG).show();
}
}
P.S. I can take the photo and save it to the picture folder (there is no R.drawable.image because i create it dynamically by creating an Uri to that file. The problem is set the imageview from the uri. There are 4 ways to set the image to the imageview. I already tried all of them. When i debug right after setting the image i can see the bitmap of the imageview and it is the picture i took by the camera.