I am getting null value when the camera is start from intent for startActivityForResult()
and getting null value which means no picture is shown.
the camera takes picture but it is not shown on the activity. Plz help me out. Here is the code for take Image Activity.
public class TakeImage extends ActionBarActivity {
private LinearLayout camera;
private LinearLayout gallery;
ImageView targetImage;
Uri fileUri = null;
Button process;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_take_image);
camera=(LinearLayout)findViewById(R.id.button);
gallery=(LinearLayout)findViewById(R.id.button1);
targetImage=(ImageView)findViewById(R.id.setImage);
process=(Button)findViewById(R.id.process);
camera.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent cameraIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(cameraIntent, RESULT_OK);
}
});
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
// TODO Auto-generated method stub
InputStream stream = null;
super.onActivityResult(requestCode, resultCode, data);
if (requestCode==1&&resultCode == RESULT_OK && data != null){
Uri targetUri = data.getData();
Bitmap bitmap;
try {
bitmap = BitmapFactory.decodeStream(getContentResolver().openInputStream(targetUri));
targetImage.setImageBitmap(bitmap);
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}