连接到Gmail时PDF的大小显示0 [英] The size of pdf is shown 0 when attached to gmail

查看:109
本文介绍了连接到Gmail时PDF的大小显示0的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

String emailAddress[] = {""};

    File externalStorage = Environment.getExternalStorageDirectory();

    Uri uri = Uri.fromFile(new File(externalStorage.getAbsolutePath() + "/" + "com.example.pdf/sample.pdf"));

    Intent emailIntent = new Intent(Intent.ACTION_SEND);
    emailIntent.putExtra(Intent.EXTRA_EMAIL, emailAddress);
    emailIntent.putExtra(Intent.EXTRA_SUBJECT, "Subject");
    emailIntent.putExtra(Intent.EXTRA_TEXT, "Text");
    emailIntent.setType("application/pdf");
    emailIntent.putExtra(Intent.EXTRA_STREAM, uri);

    startActivity(Intent.createChooser(emailIntent, "Send email using:"));

在logcat中显示的信息是:

The message shown in logcat is:

gMail Attachment URI: file:///mnt/sdcard/com.example.pdf/sample.pdf
gMail type: application/pdf
gmail name: sample.pdf
gmail size: 0

的问题是,样品PDF格式的大小为0,所以PDF格式不发送作为电子邮件的附件。谁能告诉我究竟做错了什么?

The problem is that the size of sample pdf is 0, so the pdf is not sent as an attachment in the email. Can anyone tell what am I doing wrong?

推荐答案

你是如何保存在该目录上的PDF?

How are you saving the pdf on that directory?

如果您使用的是 getExternalStorageDirectory (我假设你是),即PDF专用于您的应用程序,并且无法通过电子邮件应用程序的访问。

If you are using the getExternalStorageDirectory (i'm assuming you are), that pdf is private to your application, and can't be accessed by the email app.

如果您需要该文件私有保持你的应用程序,并且还能够通过电子邮件共享,使用的ContentProvider
http://developer.android.com/guide/topics/providers/content-provider-creating.html

If you need to keep that file private to your application, and still be able to share via email, use a ContentProvider : http://developer.android.com/guide/topics/providers/content-provider-creating.html

如果你能保持在一个共享目录中的文件,你应该使用 getExternalStoragePublicDirectory()
http://developer.android.com/guide/topics/data/data-storage.html#filesExternal

If you can keep that file on a shared directory, you should use getExternalStoragePublicDirectory(): http://developer.android.com/guide/topics/data/data-storage.html#filesExternal

这篇关于连接到Gmail时PDF的大小显示0的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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