Android 应用程序拍摄/通过电子邮件发送照片

发布于 2024-12-17 09:35:06 字数 1404 浏览 0 评论 0原文

我目前正在编写一个应用程序,在某个活动中,我们希望用户能够拍摄照片并将其通过电子邮件发送到所需的电子邮件地址。我可以分别执行这两项操作(拍照并发送照片),但是当我一起运行它们时,电子邮件客户端列表会出现在相机上......我似乎无法弄清楚为什么它没有运行在相机本身之后..有什么帮助吗?

***这是我现在拥有的:

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();
  } 
}  

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();
  } 
}  

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

琉璃繁缕 2024-12-24 09:35:06

您必须使用 startActivityForResult 来拍照。之后,您必须使用 onActivityResult 发送电子邮件:

   @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();
       }
   }

希望它会有所帮助。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文