0

Any help , Ideas I will be appropriated . Hello Guys, sorry am asking so much question these days. I designed simple android app that use the camera and show the picture is taken at the layout. Look at the attached pictures. enter image description here

Once I click the "open the Camera " button it will pop up the camera asking the use to press the camera buttom to shot or take picture. What I need here , once the camera opens, it should take picture by it self with out use the camera button , Idn if is that possible or not.

enter image description here

The next problem as shown in the picture, it requires user interference to press ok if the user like it . here in this step I need to take just one picture once is taken should go back to main activity. and store the picture in Image View . enter image description here

the last request or ideas guys how to send this pict to the email interference from the user . here is the Code -----------------------------------

public class MainActivity extends Activity {
    ImageView viewpict;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        viewpict=(ImageView) findViewById(R.id.pict_result);
        Button btn= (Button)findViewById(R.id.camera);

        btn.setOnClickListener(new OnClickListener(){

            @Override
            public void onClick(View arg0) {
                Intent intent = new Intent (android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
            //  Intent intent = new Intent (getApplicationContext(),MainActivity2.class);

                //startActivity(intent);
                startActivityForResult(intent,0);

            }

     });


    }

protected void onActivityResult( int requestCode, int resultCode,Intent data)
{
    if (requestCode==0)
    {
        Bitmap theimage = (Bitmap) data.getExtras().get("data");
        viewpict.setImageBitmap(theimage);
    }

}

}

  • 2
    **1.** Automatically snap picture? I don't know but what have you found after googling? **2.** Sending image via email (through `Intent`), you'd find a lot of questions on SO alone for this one. – Sufian Apr 17 '15 at 06:32

4 Answers4

2

First you have to save that bitmap to sdcard then you can attach that image to email.

to save bitmap to sdcard is

FileOutputStream out = null;
 try {
out = new FileOutputStream(filename);
bmp.compress(Bitmap.CompressFormat.PNG, 100, out); // bmp is your Bitmap    instance
// PNG is a lossless format, the compression factor (100) is ignored
} catch (Exception e) {
e.printStackTrace();
} 
   try {
    if (out != null) {
        out.close();
    }
} catch (IOException e) {
    e.printStackTrace();

}

and then you can read that image and attach to email

for that have a look at this link How to attach Bitmap to email android

Community
  • 1
  • 1
Moubeen Farooq Khan
  • 2,875
  • 1
  • 11
  • 26
1

To send the image through mail, you can use this:

Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND); 
emailIntent.setType("application/image");
emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, "Test Email"); 
emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT,"Test Subject"); 
emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, "From My App"); 
emailIntent.putExtra(Intent.EXTRA_STREAM,Uri.parse("file:///mnt/sdcard/Myimage.jpeg"));
startActivity(Intent.createChooser(emailIntent, "Send mail..."));
Strider
  • 4,452
  • 3
  • 24
  • 35
1

In your onActivityResult method you should open a new Activity to view the image preview, one that has an xml with an imageview, ok and cancel buttons.

Send your bitmap to this activity and put it in its imageview - the preview activity can have a static bitmap ImagePreview property.

When pressing ok, you should save image to sdcard, and then send email, as described by @Moubeen.

A B
  • 338
  • 3
  • 10
  • SO how can I make the camera takes picture or record video immediatly once the camera opens , is there any way to do that. thanks – Adel Abuaza Apr 17 '15 at 18:46
1

you can convert a bitmap into PNG in external storage.

File path = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES);
File imageFile = new File(path, getCurrentTime()+ ".png");
FileOutputStream fileOutPutStream = new FileOutputStream(imageFile);
bitmap.compress(Bitmap.CompressFormat.PNG, 80, fileOutPutStream);

fileOutPutStream.flush();
fileOutPutStream.close();  

Then, you will get URI through url.Parse(). which you can share .

Uri.parse("file://" + imageFile.getAbsolutePath());  


Intent intent= new Intent(android.content.Intent.ACTION_SEND); 
intent.setType("application/image");
intent.putExtra(android.content.Intent.EXTRA_EMAIL, "Email"); 
intent.putExtra(android.content.Intent.EXTRA_SUBJECT,"Your Subject"); 
intent.putExtra(android.content.Intent.EXTRA_TEXT, "Text"); 
intent.putExtra(Intent.EXTRA_STREAM, Uri.parse("file://" + imageFile.getAbsolutePath()));
startActivity(Intent.createChooser(intent, "mail sending"));
Samir Bhatt
  • 3,041
  • 2
  • 25
  • 39