Android应用程序采取

Android应用程序采取

本文介绍了Android应用程序采取/电子邮件发送照片的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在写一个特定的活动中,我们希望用户能够采取并通过电子邮件发送照片到所需的电子邮件地址的应用程序。我能够做到这两个(拍摄照片,并发送照片)分开,但是当我一起运行,电子邮件客户端列表通过相机来了......我似乎无法弄清楚,为什么它没有运行相机本身后..任何帮助吗?

***这里是我现在有:

 公共类PhotoHandler延伸活动{私人最终静态INT TAKE_PHOTO_ code = 1;
文件downloadedPic = NULL;
在意向;@覆盖
公共无效的onCreate(捆绑savedInstanceState){
  super.onCreate(savedInstanceState);
  的setContentView(R.layout.mnwv_main);  downloadedPic = takeandReturn(本);
}@覆盖
公共无效的onActivityResult(INT申请code,INT结果code,意图数据)
{  尝试{
      意图picMessageIntent =新意图(android.content.Intent.ACTION_SEND);
      picMessageIntent.setType(图像/ JPEG);
      picMessageIntent.putExtra(Intent.EXTRA_STREAM,Uri.fromFile(downloadedPic));
        picMessageIntent.putExtra(Intent.EXTRA_EMAIL,新的String [] {});
      picMessageIntent.putExtra(Intent.EXTRA_SUBJECTMNWV - 看看这个照片!);
        picMessageIntent.putExtra(Intent.EXTRA_TEXT,***请说明采取下面的照片(包括您的姓名,位置等)... ***。);
      startActivity(Intent.createChooser(picMessageIntent,发送图片使用:));
  }赶上(例外五){
      Log.e(TAG,sendPictureMessage()启动失败的活动,E);
      Toast.makeText(这一点,不处理,Toast.LENGTH_LONG).show();
  }
}


解决方案

您必须使用startActivityForResult采取的照片。之后,你必须使用的onActivityResult发送电子邮件:

  @覆盖
   公共无效的onActivityResult(INT申请code,INT结果code,意图数据)
   {
       // TODO:测试要求code和结果code
       尝试{
           意图picMessageIntent =新意图(android.content.Intent.ACTION_SEND);
           picMessageIntent.setType(图像/ JPEG);
           picMessageIntent.putExtra(Intent.EXTRA_STREAM,Uri.fromFile(downloadedPic));
           startActivity(Intent.createChooser(picMessageIntent,发送图片使用:));
       }赶上(例外五){
           Log.e(TAG,sendPictureMessage()启动失败的活动,E);
           Toast.makeText(这一点,不处理,Toast.LENGTH_LONG).show();
       }
   }

希望这会有所帮助。

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();
  }
}
解决方案

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.

这篇关于Android应用程序采取/电子邮件发送照片的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-28 02:22