English 中文(简体)
安德列:我如何在电子邮件中附上临时的、产生的形象?
原标题:Android: How do I attach a temporary, generated image to an email?

我有计划生成的形象,我希望通过<代码>作为附件发送。 行动_SEND和EXTRA_STREAM方法。

但是,如何做到这一点?

我的第一项尝试(写给我的<代码>context.getCacheDir( based file path)似乎是在电子邮件预告(没有图像预约,但附有档案名称和icon)中工作,但附文从来就没有到达接收方。 我猜测,这样做与所生成文件上的许可有关,但如何避免这种情况? 我是否需要在这些产生的档案上建立更宽容的环境(以便电子邮件活动能够查阅)? 这是否甚至有可能给 app子fold子?

是否有另一个档案地点更适合书写我的档案? 我审议了下载的夹,但认为这只是一个难得的地点,在电子邮件发出之前只需要存在。

我甚至试图在<代码>数据:image/png;base64,ABCD...风格URI中全貌相。 这在Gmail preview(attachment icon,但无档案名称)中也显示,但并未造成接收方的附属关系。

是否有任何人能够以任何手段在电子邮件意向中附上一幅生成的形象? 我可能忽略哪些选择?

最佳回答

我的问题是两部分:

  1. context.getCacheDir() is private to your app. You can t put something there and expect another app to be able to access it.
  2. I misunderstood what MIME type I should have been using. Even though I was sending email text, I really needed to specify image/png for the sake of my attachment.

此外,研究表明,将(可能较大的)图像放在主要记忆上不是一个好的想法,即使你将立即清理。

一旦我做这些事情,把我制作的图像写到SD卡上的一个公共场所,那就算是罚款。

因此,概览:

www.un.org/Depts/DGACM/index_spanish.htm 请求SD 文件 查阅你的明文<>

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

<>确保SD ∗∗∗∗

if (!Environment.MEDIA_MOUNTED.equals(Environment.getExternalStorageState())) 
{
    //Bail gracefully
}

www.un.org/Depts/DGACM/index_spanish.htm 制作SD卡的名录

File pngDir = new File(
    Environment.getExternalStorageDirectory(),   
    //Loose convention inferred from app examples
    "Android/data/com.somedomain.someapp/flotsam");

if (!pngDir.exists())
    pngDir.mkdirs();

www.un.org/Depts/DGACM/index_spanish.htm 向该名录撰写你的文件,并捕获Uri

File pngFile = new File(pngDir, "jetsam.png");
//Save file encoded as PNG
Uri pngUri = Uri.fromFile(pngFile);

www.un.org/Depts/DGACM/index_spanish.htm 建立<条码> 参考标准

Intent intent = new Intent(android.content.Intent.ACTION_SEND);
intent.setType("image/png"); //
intent.putExtra(android.content.Intent.EXTRA_EMAIL, new String[] { "someone@somewhere.com" });
intent.putExtra(android.content.Intent.EXTRA_SUBJECT, "Portable Network Graphics");
intent.putExtra(android.content.Intent.EXTRA_CC, new String[] { "carbon@somewhere.com" });
intent.putExtra(Intent.EXTRA_TEXT, "Something textual");
intent.putExtra(Intent.EXTRA_STREAM, pngUri);

www.un.org/Depts/DGACM/index_spanish.htm 然后开始活动。

context.startActivity(Intent.createChooser(intent, "Something Pithy"));

然后确保你清理所有东西......

<><>Caveat 1

似乎有更多的人支持提供专门的SD卡片目录,但不是在我要求的SDK版本中提供地图。

<><>Caveat 2

这是最终为我工作的解决办法概览。 这不一定是一种“最佳做法”方法。

<><>Caveat 3

这确实意味着,申请必须安装SD卡,以便有图像附录,但我使用的是完全可以接受的。 你的里程可能有所不同。 如果无法拿到SD卡,我就向电子邮件发出一份友好照会,解释为何不能附上图像以及如何纠正这种情况。

问题回答

我刚刚谈到同一问题(在我的案件中附上一份案文)。 如果你看见安乐木,其原因是:

02-28 21:01:28.434: E/Gmail(19673): file:// attachment paths must point to file:///mnt/sdcard. Ignoring attachment file:///data/data/com.stephendnicholas.gmailattach/cache/Test.txt

作为一项工作(如HRJ所述),你可以使用内容提供人,在您的申请书中提供查阅文件的内部藏匿处,以便电子邮件能够附上。 I ve Just written up a blog post on how to do it.

希望得到一些帮助:

tableLayout.buildDrawingCache();
        Bitmap test = Bitmap.createBitmap(tableLayout.getDrawingCache());
        tableLayout.destroyDrawingCache();

        Log.d("Image", test.toString());

        String path = Environment.getExternalStorageDirectory().toString(); 
        Log.d("Path", path);
        File file = new File(path,"mail_image.png");
        Uri pngUri = Uri.fromFile(file);
        Log.d("Real Image Path", pngUri.toString());

        Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND);
        emailIntent.setType("image/png");
        emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL, "email to"); 
        emailIntent.putExtra(android.content.Intent.EXTRA_SUBJECT,"Subject"); 
        emailIntent.putExtra(android.content.Intent.EXTRA_TEXT, "From My App"); 
                    emailIntent.putExtra(android.content.Intent.EXTRA_STREAM, pngUri );

        startActivity(Intent.createChooser(emailIntent, "Send mail..."));




相关问题
Angle brackets in php

I want to store angle brackets in a string in PHP because i want to eventually use mail() to send an HTML email out. The following is the code that doesn t seem to work. while(...) { $msg .= "<...

authlogic auto_register feature using my options

I have auto registration working with authlogic using gaizka s version of authlogic_openid which I found on Github since pelle s original addition of the feature seemed to cause issues. http://...

Zend 邮件问题,涉及外国char子+ com子

泽斯德邮局在名称被定为具有外国性质(如“保”)和 com(”)的物品时,就放弃了一种例外(因为邮局(邮局)退回假)。 重新提出以下守则。

How to track an email in Java?

How I can track an email? I m using java on the server side for sending emails. I want to track whether it is delivered , opened, etc... How I can do that ?

Web Link in a mail is not rendering as link in yahoo

string from = "abc@gmail.com"; string to = "xyz@gmail.com,xyz@yahoo.co.in"; string password="abcxyz"; MailMessage mail = new System.Net.Mail.MailMessage(); mail.To.Add(to); mail.From = new ...

SharePoint - Approaching Website Storage Limit Email

How can i go about changing the distribution list as well as the email text for the email that goes out to site collection admin when a site collection approaches it s size limit? Thanks for your ...

How to create an email mailing list

Im creating a coming soon page for a website im developing, and im adding an option for the user to enter their email address so we can email them when the site is up. How do I do this?

CCNet email does not include MSBuild results

We re using CCNet 1.4.4.83 but when an MSBuild task fails, we don t get the MSBuild results (i.e. missing file or whatever reason the compile failed) in the email notification. I do see the build ...

热门标签