This is my code to launch the camera and take a photo and send as Intent to another activity:
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
view = inflater.inflate(R.layout.fragment_add_image, container, false);
button = (Button)view.findViewById(R.id.addImage);
button.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Toast.makeText(getActivity(),"Launching Camera",Toast.LENGTH_SHORT).show();
Intent cameraIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
cameraIntent.putExtra("putSomething", true);
startActivityForResult(cameraIntent, CAMERA_REQUEST);
}
});
return view;
}
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (resultCode == Activity.RESULT_OK)
{
BitmapFactory.Options options = new BitmapFactory.Options();
options.inSampleSize = 8;
//ImageView jpgView = (ImageView)findViewById(R.id.imageView1);
Bitmap receipt = BitmapFactory.decodeFile(photo.toString(),options);
Intent imagepass = new Intent(getActivity(),StoreImage.class);
imagepass.putExtra("imagepass", receipt );
startActivity(imagepass);
}
}
Now in the receiving activity how do i show the photo captured by the camera, what should i add to the xml file to display the image in a GridView
here's my code:
public class StoreImage extends AppCompatActivity {
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_store_image);
//creating view ids
Bitmap receiptimage = (Bitmap) getIntent().getExtras().getParcelable("imagepass");
receipt.setImageBitmap(receiptimage);
}
}