I'm doing a photo editor app in android and I have two image buttons(one for the camera and the other for gallery). When I capture the photo with the camera or select the photo from the gallery I want the photo to be displayed in another activity on image view. I just wrote some of the code for the camera,but it doesn't work. If someone can help me , I'll be very grateful. I'm a newbie to programming.
manifest.xml
<manifest ..>
<uses-feature android:name = "android.hardware.camera" android:required="false"/>
first activity:
public class MainActivity extends Activity {
private static int IMG_RESULT = 1;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
ImageButton take_photo = (ImageButton) findViewById(R.id.cameraButton);
ImageButton get_photo = (ImageButton) findViewById(R.id.galleryButton);
take_photo.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
Intent intent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(intent,0);
}
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if(requestCode == 0 && resultCode == RESULT_OK)
{
Bitmap bitmap = (Bitmap)data.getExtras().get("data");
Intent intent = new Intent(this,ShowPhotoActivity.class);
intent.putExtra("BitmapImage",bitmap);`
startActivity(intent);`
second activity:
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_show_photo);
ImageView showPhoto = (ImageView) findViewById(R.id.imageView);
Bitmap bitImage = getIntent().getParcelableExtra("BitmapImage");
showPhoto.setImageBitmap(bitImage);