java - 如何通过电子邮件发送从相机拍摄的照片 Android

标签 java android eclipse

我正在编写一个用于教育目的的应用程序,用户可以在其中从相机拍摄照片并通过电子邮件发送。我写了几乎所有的代码,除了代码 whi 但我不知道该怎么做,因为我正在学习 android。这是我的代码,我应该在这段代码中添加什么:

package com.umer.practice2;

 import java.io.IOException;

 import android.app.Activity;
 import android.content.Intent;
 import android.graphics.Bitmap;
 import android.os.Bundle;
 import android.view.View;
 import android.widget.Button;
 import android.widget.EditText;
 import android.widget.ImageButton;
 import android.widget.ImageView;
 import android.widget.TextView;

 public class SendPhoto extends Activity implements View.OnClickListener{

TextView tv1,tv2;
EditText e1,e2;
ImageView pi;
ImageButton pb;
Button pb1,pb2;
Intent photo;
Bitmap bmp;
@Override
protected void onCreate(Bundle savedInstanceState) {
    // TODO Auto-generated method stub
    super.onCreate(savedInstanceState);
    setContentView(R.layout.sendphoto);

    pb1.setOnClickListener(this);
    pb2.setOnClickListener(this);

    pb.setOnClickListener(this);
    initializeView();
}

private void initializeView() {
    // TODO Auto-generated method stub
    tv1= (TextView) findViewById(R.id.pt1);
    tv2= (TextView) findViewById(R.id.pt2);

    e1= (EditText) findViewById(R.id.pe1);
    e2= (EditText) findViewById(R.id.pe2);

    pi= (ImageView) findViewById(R.id.p1);
    pb= (ImageButton) findViewById(R.id.pib2);

    pb1= (Button) findViewById(R.id.pbut1);
    pb2= (Button) findViewById(R.id.pbut2);
}

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

    switch(v.getId())
    {
    case R.id.pbut1:
        String email[]={e2.getText().toString()};

        Intent emailIntent= new Intent(android.content.Intent.ACTION_SEND);
        emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, email);
        emailIntent.setType("image/jpeg");
        startActivityForResult(emailIntent, 1);
        break;
    case R.id.pib2:
        photo= new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
        startActivityForResult(photo,2); 
        break;
    case R.id.pbut2:
        try {
            getApplicationContext().setWallpaper(bmp);
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        break;
    }
}

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    // TODO Auto-generated method stub
    super.onActivityResult(requestCode, resultCode, data);

    Bundle extras = data.getExtras();
    bmp = (Bitmap) extras.get("data");
    pi.setImageBitmap(bmp);
}

}

最佳答案

在您的 onActivityResult 方法中,您应该将位图保存到 SD 卡上的文件中,接下来您应该将文件附加到电子邮件 Intent 。

如何将图像保存到SD卡上的文件中 How to save a bitmap into phone's gallery?

如何将文件附加到电子邮件 Intent : Trying to attach a file from SD Card to email

关于java - 如何通过电子邮件发送从相机拍摄的照片 Android,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11850864/

相关文章:

eclipse - 如何在Eclipse中修改EL打开模板?

java - 如何使用 Eclipse 将 GWT 项目导出为可执行 JAR 文件?

java - 如何在 Eclipse 程序中启用 Java 关键字断言?

java - 使用 Spring Mail 将电子邮件保存到已发送文件夹中

Java Swing : Listening and repeating events from one frame in another

android - ScrollView 没有重力。如何使 ScrollView 内的内容为中心

android - Cordova Android 应用程序和用户权限

java - Spring安全Oauth2 token 错误: "Missing grant type"

java - 为什么我的 HTTPS 文件下载会损坏 .zip 文件?

android - 如何在 Android 的菜单中使用 CheckBox?