0

I write this code ti take a picture and then send it to other activity. but every time I run it camera dosent start and only intent 2 in takephoto class start new activity. and if I remove this part camera start:

  Intent intent2 = new Intent (welcom.this, MainActivity.class);
    startActivity(intent2);
    intent2.putExtra("mImageUri", imageUri);

the code:

public class welcom extends Activity{
private static final int TAKE_PICTURE = 1;    
private Uri imageUri;

@Override
protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    setContentView(R.layout.welcom);

    Button camera= (Button) findViewById(R.id.camera);
    Button gallery= (Button) findViewById(R.id.gallery);


    camera.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View arg0) {




            takePhoto();




        }
    });

gallery.setOnClickListener(new OnClickListener() {

        @Override
        public void onClick(View arg0) {
            // TODO Auto-generated method stub

        }
    });
}








public void takePhoto() {
    Intent intent = new Intent("android.media.action.IMAGE_CAPTURE");
    File photo = new File(Environment.getExternalStorageDirectory(),  "Pic.jpg");
    intent.putExtra(MediaStore.EXTRA_OUTPUT,
            Uri.fromFile(photo));
    imageUri = Uri.fromFile(photo);
    startActivityForResult(intent, TAKE_PICTURE);

    Intent intent2 = new Intent (welcom.this, MainActivity.class);
    startActivity(intent2);
    intent2.putExtra("mImageUri", imageUri);
}}
sara sara
  • 47
  • 9

2 Answers2

0

Try this:

Intent intent2 = new Intent (welcom.this, MainActivity.class);
intent2.putExtra("mImageUri", imageUri);
startActivity(intent2);
Osama Aftab
  • 1,161
  • 9
  • 15
0

You are first opening the new activity and then adding the image to it. shuffle the order and problem solved.

Other:

You will have to pass photo by converting it to byte array. take a look at that questin it solves the problem

Take photo and pass it to another activity

Community
  • 1
  • 1
Zain ul abdeen
  • 155
  • 1
  • 5
  • 15