1

我正在编写一个 android 应用程序,该应用程序具有发送带有特定文档附件的电子邮件的功能。这是有效的,但是当我将其附加到电子邮件时,该附件称为“peroneal.pdf”(作为一种意图,我确定这是问题所在)在收到电子邮件时变为“2131034113.pdf” . 如何更改它以使收到的文档具有原始名称?它与命名意图有关吗?如果是这样,我该怎么做?在此先感谢您的帮助,我附上了代码片段:

Intent i = new Intent(Intent.ACTION_SEND);
i.setType("message/rfc822");
i.putExtra(Intent.EXTRA_EMAIL  , new String[]{value.toString()});
i.putExtra(Intent.EXTRA_SUBJECT, "Tendon Email");
i.putExtra(Intent.EXTRA_TEXT   , "The info is attached, just hit send.");


String rawFolderPath = "android.resource://" + getPackageName() + "/" + R.raw.peroneal;

Uri emailUri = Uri.parse(rawFolderPath);
i.putExtra(Intent.EXTRA_STREAM, emailUri);
i.setType("application/pdf");


try {
     startActivity(Intent.createChooser(i, "Send mail..."));

} catch (android.content.ActivityNotFoundException ex) {
        Toast.makeText(PTSlideShow.this, "There are no email clients installed.", Toast.LENGTH_SHORT).show();
    }
4

1 回答 1

1

This is working but the attachment, which is called "peroneal.pdf"

No, it is not called "peroneal.pdf", at least not on the device.

You may have a file named of peroneal.pdf on your local filesystem. That is largely lost when you package it as a resource, as you apparently have.

What the other process will see is android.resource://.../2131034113, where 2131034113 is the decimal value of R.raw.peroneal (and ... is your app's package name).

How do I change it so that the received document has the original name?

Well, you will increase your odds by using a Uri that actually has peroneal.pdf in it. For example, you could copy your raw resource out to external storage and use a File-based Uri instead. Or, serve up the attachment via an openFile()-based ContentProvider, where you support a Uri that ends in peroneal.pdf.

However, bear in mind that you are asking other apps to send email on your behalf. How those emails get created and packaged is up to the authors of those other email apps. There is no guarantee, at all, that your attachment will be named based on the last segment of the Uri. Probably there are many email apps that will take this approach, but I would not be the least bit surprised if there are some that will not.

于 2012-11-08T22:28:56.180 回答