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 に答える