Android应用程序发送图像通过电子邮件 [英] Android App to Send Images Via Email

查看:112
本文介绍了Android应用程序发送图像通过电子邮件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好了再一次,我在一路过来我这里头,同时学习机器人。之后终于发展我简单的小应用程序,我想使用一些具有本机应用程序的好处。

因此​​,项目一期,做一个页面,该页面可以通过电子邮件(无论是从画廊或摄像头)将图像发送

从本质上讲它是一种选择,并通过电子邮件发送,但我甚至不知道从哪里开始。

我发现了一些code表示别人问的时; Android应用程序采取/电子邮件发送照片

我想这一点,但得到的各种错误,从偏食,replating为 downloadedPic 部分。

如果有人能请看看,并告诉我在做到这一点的最好办法,这将是惊人的。像往常一样,对不起我的beginers愚蠢,但我想每个人都有学习的地方。

这是我的.JAVA AT preSENT

 公共类图片扩展活动{

@覆盖
公共无效的onCreate(包savedInstanceState){
    super.onCreate(savedInstanceState);
    的setContentView(R.layout.activity_photos);
    getActionBar()setDisplayHomeAsUpEnabled(真)。
}

@覆盖
公共布尔onCreateOptionsMenu(功能菜单){
    。getMenuInflater()膨胀(R.menu.activity_photos,菜单);
    返回true;
}
 

这是我的.XML AT preSENT     

 <的TextView
    机器人:layout_width =WRAP_CONTENT
    机器人:layout_height =WRAP_CONTENT
    机器人:文本=请选择下面的选项,选择并上传照片到
    DCC所选择的项目......
    工具:照片上下文=
    机器人:textAppearance =机器人:ATTR / textAppearanceMedium/>


< / LinearLayout中>
 

解决方案

首先你应该做的是使用文件获得图像的存储路径,

 文件*照片=新File(Environment.getExternalStorageDirectory()+"/Android/data/"+getApplicationContext().getPackageName()+"/Fault", imagename +。PNG);
 

然后再转换在文件路径乌里

 乌里imageuri = Uri.fromFile(照片);
 

最后通过电子邮件使用发送图片你的 imageuri

 意图send_report =新的意图(Intent.ACTION_SEND);
                                        send_report.putExtra(Intent.EXTRA_EMAIL,新的String [] {email_emailid});
                                        send_report.putExtra(Intent.EXTRA_SUBJECT,EMAIL_SUBJECT);
                                        send_report.putExtra(Intent.EXTRA_STREAM,imageuri);
                                        send_report.putExtra(Intent.EXTRA_TEXT,email_body);
                                        send_report.setType(text / plain的);
                                        send_report.setType(图像/ PNG);
                                        startActivityForResult(Intent.createChooser(send_report,选择电子邮件客户端),77);
 

希望它帮助。

Ok once again, I am in way over my head here while learning android. After finally developing my simple little app, I am trying to use some of the benefits of having a native app.

So, project one, make a page which can send images via email (either from the gallery or camera)

Essentially its a select and send via email, but I don't even know where to start.

I found some code that somebody else was asking about at; Android App Take/ Email Photo

I tried this, but get all sorts of errors from eclipse, replating to downloadedPic section.

If somebody could please take a look and advise me on the best way to do this, that would be amazing. As usual sorry for my beginers stupidity, but I guess everyone has to learn somewhere

THIS IS MY .JAVA AT PRESENT

public class Photos extends Activity {

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_photos);
    getActionBar().setDisplayHomeAsUpEnabled(true);
}

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(R.menu.activity_photos, menu);
    return true;
}

THIS IS MY .XML AT PRESENT

<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="Please chose the options below to select and upload photos into the 
    DCC for the selected project..."
    tools:context=".Photos"
    android:textAppearance="?android:attr/textAppearanceMedium" />


</LinearLayout>

解决方案

First what should you do is get the image storage path by using the file,

 File *photo = new File(Environment.getExternalStorageDirectory()+"/Android/data/"+getApplicationContext().getPackageName()+"/Fault", imagename+".png");

Then Convert that file path in to Uri

Uri imageuri = Uri.fromFile(photo); 

Finally send it the image via email using your imageuri

Intent send_report = new Intent(Intent.ACTION_SEND);
                                        send_report.putExtra(Intent.EXTRA_EMAIL, new String[]{ email_emailid}); 
                                        send_report.putExtra(Intent.EXTRA_SUBJECT, email_subject);
                                        send_report.putExtra(Intent.EXTRA_STREAM, imageuri);
                                        send_report.putExtra(Intent.EXTRA_TEXT, email_body);  
                                        send_report.setType("text/plain");
                                        send_report.setType("image/png");
                                        startActivityForResult(Intent.createChooser(send_report, "Choose an Email client"), 77);

Hope it helps.

这篇关于Android应用程序发送图像通过电子邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆