gpt4 book ai didi

java - 我如何以编程方式发送图片作为电子邮件的一部分

转载 作者:行者123 更新时间:2023-12-01 09:21:24 24 4
gpt4 key购买 nike

嗨,大家好,为 friend 制作了一个简单的电子邮件应用程序。它会向他发送部分业务的信息。但有时也需要附上照片。我使用这段代码解决了打开相机并拍摄照片并将其保存到设备内存的问题

 public class CameraDemoActivity extends Activity {
int TAKE_PHOTO_CODE = 0;
public static int count = 0;

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);

// Here, we are making a folder named picFolder to store
// pics taken by the camera using this application.
final String dir = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES) + "/picFolder/";
File newdir = new File(dir);
newdir.mkdirs();

Button capture = (Button) findViewById(R.id.btnCapture);
capture.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {

// Here, the counter will be incremented each time, and the
// picture taken by camera will be stored as 1.jpg,2.jpg
// and likewise.
count++;
String file = dir+count+".jpg";
File newfile = new File(file);
try {
newfile.createNewFile();
}
catch (IOException e)
{
}

Uri outputFileUri = Uri.fromFile(newfile);

Intent cameraIntent = new Intent(MediaStore.ACTION_IMAGE_CAPTURE);
cameraIntent.putExtra(MediaStore.EXTRA_OUTPUT, outputFileUri);

startActivityForResult(cameraIntent, TAKE_PHOTO_CODE);
}
});
}

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);

if (requestCode == TAKE_PHOTO_CODE && resultCode == RESULT_OK) {
Log.d("CameraDemo", "Pic saved");
}
}

}

我现在如何将其附加到应用程序中的电子邮件中?任何帮助总是感激谢谢

最佳答案

我猜您将使用 Intent 发送邮件,只需在构建您的 Intent 时添加此内容即可:

intent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(file));

关于java - 我如何以编程方式发送图片作为电子邮件的一部分,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40142958/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com