java-我需要通过邮件从相机发送图像

java-我需要通过邮件从相机发送图像,第1张

概述我对androidstudio和其他东西有点陌生…所以我被卡住了.我需要捕获图片并将其发送给电子邮件.`公共类MainActivity扩展Activity实现OnClickListener{EditTexteditTextEmail,editTextSubject,editTextMessage;ButtonbtnSend,btnAttachment;Stringemail,subject,messag

我对android studio和其他东西有点陌生…所以我被卡住了.我需要捕获图片并将其发送给电子邮件.`公共类MainActivity扩展Activity实现OnClickListener {

EditText editTextEmail, editTextSubject, editTextMessage;button btnSend, btnAttachment;String email, subject, message, attachmentfile;Uri URI = null;private static final int PICK_FROM_galLERY = 101;int columnIndex;protected static final int CAMERA_PIC_REQUEST = 0;Bitmap thumbnail;file pic;@OverrIDeprotected voID onCreate(Bundle savedInstanceState) {    super.onCreate(savedInstanceState);    setContentVIEw(R.layout.activity_main);    editTextEmail = (EditText) findVIEwByID(R.ID.editTextTo);    editTextSubject = (EditText) findVIEwByID(R.ID.editTextSubject);    editTextMessage = (EditText) findVIEwByID(R.ID.editTextMessage);    btnAttachment = (button) findVIEwByID(R.ID.buttonAttachment);    btnSend = (button) findVIEwByID(R.ID.buttonSend);    btnSend.setonClickListener(this);    btnAttachment.setonClickListener(this);}@OverrIDepublic voID onClick(VIEw v) {    if (v == btnAttachment) {        opengallery();    }    if (v == btnSend) {        try {            email = editTextEmail.getText().toString();            subject = editTextSubject.getText().toString();            message = editTextMessage.getText().toString();            final Intent emailintent = new Intent (Intent.ACTION_SEND);           // emailintent.setType("message/rfc822");            emailintent.putExtra(androID.content.Intent.EXTRA_EMAIL,                    new String[] { email });            emailintent.putExtra(androID.content.Intent.EXTRA_SUBJECT,                    subject);            if (URI != null) {                emailintent.putExtra(Intent.EXTRA_STREAM, URI.fromfile(pic));            }            emailintent.setType("image/png");            emailintent.putExtra(androID.content.Intent.EXTRA_TEXT, message);            this.startActivity(Intent.createChooser(emailintent,                    "Sending email..."));        } catch (Throwable t) {            Toast.makeText(this,                    "Request Failed try again: " + t.toString(),                    Toast.LENGTH_LONG).show();        }    }}public voID opengallery(){    Intent cameraIntent = new Intent(androID.provIDer.MediaStore.ACTION_IMAGE_CAPTURE);    startActivityForResult(cameraIntent, CAMERA_PIC_REQUEST);}protected voID onActivityResult(int requestCode, int resultCode, Intent data) {    if (requestCode == CAMERA_PIC_REQUEST) {        thumbnail = (Bitmap) data.getExtras().get("data");        ImageVIEw image = (ImageVIEw) findVIEwByID(R.ID.imageVIEw1);        image.setimageBitmap(thumbnail);        try {            file root = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_PICTURES);            if (root.canWrite()){                pic = new file(root, "pic.png");                fileOutputStream out = new fileOutputStream(pic);                thumbnail.compress(Bitmap.CompressFormat.PNG, 100, out);                out.flush();                out.close();            }        } catch (IOException e) {            Log.e("broKEN", "Could not write file " + e.getMessage());        }    }}}

那是我的代码,我可以用它拍照或发送没有照片的电子邮件.

附言我发现自己的错误.清单文件中没有权限的地方

解决方法:

使用意图调用您的邮件应用程序并附加图像

Intent emailintent = new Intent(androID.content.Intent.ACTION_SEND); emailintent.setType("application/image");emailintent.putExtra(androID.content.Intent.EXTRA_EMAIL, new String[]{strEmail}); emailintent.putExtra(androID.content.Intent.EXTRA_SUBJECT,"Add your Subject Here"); emailintent.putExtra(androID.content.Intent.EXTRA_TEXT, "hey, I send you this Image from my Camera App"); emailintent.putExtra(Intent.EXTRA_STREAM, Uri.parse("Your ImagePath"));startActivity(Intent.createChooser(emailintent, "Send mail..."));
总结

以上是内存溢出为你收集整理的java-我需要通过邮件从相机发送图像全部内容,希望文章能够帮你解决java-我需要通过邮件从相机发送图像所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1120726.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-29
下一篇 2022-05-29

发表评论

登录后才能评论

评论列表(0条)

保存