Java Eclipse电子邮件+;图画
我正在制作一个应用程序,现在将创建一封电子邮件,其中包含一条可恨的消息,使用您对几个问题的回答。我想知道我如何才能添加一个功能,使我可以采取的照片,然后通过电子邮件发送给那个人,我相信我有一些事情设置正确,但我不知道如何电子邮件它。我的代码如下。我还可以提供我尚未添加的任何其他信息Java Eclipse电子邮件+;图画,java,android,xml,eclipse,Java,Android,Xml,Eclipse,我正在制作一个应用程序,现在将创建一封电子邮件,其中包含一条可恨的消息,使用您对几个问题的回答。我想知道我如何才能添加一个功能,使我可以采取的照片,然后通过电子邮件发送给那个人,我相信我有一些事情设置正确,但我不知道如何电子邮件它。我的代码如下。我还可以提供我尚未添加的任何其他信息 package com.example.first_app; import java.io.IOException; import java.io.InputStream; import android.app.
package com.example.first_app;
import java.io.IOException;
import java.io.InputStream;
import android.app.Activity;
import android.app.WallpaperManager;
import android.content.DialogInterface.OnClickListener;
import android.content.Intent;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
public class Email extends Activity implements View.OnClickListener{
EditText personsEmail, intro, personsName, stupidThings, hatefulAction,
outro;
String emailAdd, beginning, name, stupidAction, hatefulAct, out;
Button sendEmail;
Button takePicture;
ImageView Picture;
final static int Camera_data = 0;
Bitmap bmp;
Intent i;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.email);
initializeVars();
sendEmail.setOnClickListener(this);
takePicture.setOnClickListener(this);
InputStream is = getResources().openRawResource(R.drawable.ic_launcher);
bmp = BitmapFactory.decodeStream(is);
}
private void initializeVars() {
// TODO Auto-generated method stub
personsEmail = (EditText) findViewById(R.id.etEmails);
intro = (EditText) findViewById(R.id.etIntro);
personsName = (EditText) findViewById(R.id.etName);
stupidThings = (EditText) findViewById(R.id.etThings);
hatefulAction = (EditText) findViewById(R.id.etAction);
outro = (EditText) findViewById(R.id.etOutro);
sendEmail = (Button) findViewById(R.id.bSentEmail);
takePicture = (Button) findViewById(R.id.take_Picture);
Picture = (ImageView) findViewById(R.id.iv_Returned_Picture);
}
public void onClick(View v) {
// TODO Auto-generated method stub
convertEditTextVarsIntoStringsAndYesThisIsAMethodWeCreated();
String emailaddress[] = { emailAdd };
String message = "Well hello "
+ name
+ " I just wanted to say "
+ beginning
+ ". Not only that but I hate when you "
+ stupidAction
+ ", that just really makes me crazy. I just want to make you "
+ hatefulAct
+ ". Welp, thats all I wanted to chit-chatter about, oh and"
+ out
+ '\n' + "PS. I think I love you... ";
Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, emailaddress);
emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, "I hate you");
emailIntent.setType("plain/text");
emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, message);
startActivity(emailIntent);
}
private void convertEditTextVarsIntoStringsAndYesThisIsAMethodWeCreated() {
// TODO Auto-generated method stub
emailAdd = personsEmail.getText().toString();
beginning = intro.getText().toString();
name = personsName.getText().toString();
stupidAction = stupidThings.getText().toString();
hatefulAct = hatefulAction.getText().toString();
out = outro.getText().toString();
}
@Override
protected void onPause() {
// TODO Auto-generated method stub
super.onPause();
finish();
}
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
// TODO Auto-generated method stub
super.onActivityResult(requestCode, resultCode, data);
if (resultCode == RESULT_OK){
Bundle extras = data.getExtras();
bmp = (Bitmap) extras.get("data");
Picture.setImageBitmap(bmp);
}
}
}
这将显示一个可用于发送电子邮件的电子邮件客户端列表。您只需启动一个Intent,即可让Android为您处理邮件:
final Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND_MULTIPLE); //allow multiple attachments
emailIntent.setType("plain/text"); //limits how Android handles the "send" request to email rather than Facebook, Peep, etc.
emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT, getText(R.string.subject)); //set the email subject line
ArrayList<Uri> uris = new ArrayList<Uri>(); //multiple attachments must be added via list object
File root = Environment.getExternalStorageDirectory(); //root filepath
//get images to add to email
File fileIn = new File(root, "image.png");
Uri u = Uri.fromFile(fileIn);
uris.add(u);
//get another image to add to email
fileIn = new File(root, "image2.jpg");
u = Uri.fromFile(fileIn);
uris.add(u);
//add images to email
emailIntent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, uris);
AdminActivity.this.startActivity(Intent.createChooser(emailIntent, "Send mail..."));
final Intent emailIntent=新意图(android.content.Intent.ACTION\u SEND\u MULTIPLE)//允许多个附件
emailIntent.setType(“纯/文本”)//限制Android处理“发送”电子邮件请求的方式,而不是Facebook、Peep等。
emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT,getText(R.string.SUBJECT))//设置电子邮件主题行
ArrayList URI=新的ArrayList()//必须通过列表对象添加多个附件
文件root=Environment.getExternalStorageDirectory()//根文件路径
//获取要添加到电子邮件的图像
File fileIn=新文件(根,“image.png”);
uriu=Uri.fromFile(fileIn);
添加(u);
//获取要添加到电子邮件中的其他图像
fileIn=新文件(根,“image2.jpg”);
u=Uri.fromFile(fileIn);
添加(u);
//将图像添加到电子邮件
emailIntent.putParcelableArrayListExtra(Intent.EXTRA\u流,URI);
AdminActivity.this.startActivity(Intent.createChooser(emailIntent,“发送邮件…”);
您还可以查看如何启动照相机,并使用它返回的图像uri执行某些操作。我不完全确定第一句话的意思。。