Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
503 views
in Technique[技术] by (71.8m points)

Android App Take/ Email Photo

I am currently writing an app that within a certain activity, we want the user to be able to take and email a photo to a desired email address. I am able to do both of these (take a photo, and send a photo) separately, BUT when I run them together, the email client list comes up over the camera... I cant seem to figure out why it is not running after the camera itself.. Any help?

***Here is what I have now:

public class PhotoHandler extends Activity {

private final static int TAKE_PHOTO_CODE = 1;
File downloadedPic = null;
Intent in;

@Override
public void onCreate(Bundle savedInstanceState) {
  super.onCreate(savedInstanceState);
  setContentView(R.layout.mnwv_main);

  downloadedPic = takeandReturn(this);
}

@Override
public void onActivityResult(int requestCode, int resultCode, Intent data)
{

  try {            
      Intent picMessageIntent = new Intent(android.content.Intent.ACTION_SEND);            
      picMessageIntent.setType("image/jpeg");
      picMessageIntent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(downloadedPic));
        picMessageIntent.putExtra(Intent.EXTRA_EMAIL  , new String[]{});
      picMessageIntent.putExtra(Intent.EXTRA_SUBJECT, "MNWV - Check Out This Photo!");
        picMessageIntent.putExtra(Intent.EXTRA_TEXT   , "*** Please Describe the Photo Taken Below (Include Your Name, Location, etc.)... ***");
      startActivity(Intent.createChooser(picMessageIntent, "Send Picture Using: ")); 
  } catch (Exception e) {
      Log.e("TAG", "sendPictureMessage() failed to start activity.", e);
      Toast.makeText(this, "No handler", Toast.LENGTH_LONG).show();
  } 
}  
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You must use startActivityForResult for taking the photo. After that you must use onActivityResult to send email:

   @Override
   public void onActivityResult(int requestCode, int resultCode, Intent data)
   {
       // TODO: Test for requestCode and resultCode
       try {            
           Intent picMessageIntent = new Intent(android.content.Intent.ACTION_SEND);            
           picMessageIntent.setType("image/jpeg");
           picMessageIntent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(downloadedPic));
           startActivity(Intent.createChooser(picMessageIntent, "Send Picture Using: "));
       } catch (Exception e) {
           Log.e("TAG", "sendPictureMessage() failed to start activity.", e);
           Toast.makeText(this, "No handler", Toast.LENGTH_LONG).show();
       }
   }

Hope it will help.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...