我使用android intent将sd卡中的pdf文件发送到电子邮件地址。它显示我附加的pdf文件,但这个附加文件在reviver端消失。我不知道我做错了什么。这是我的代码
String[] mailto = {"me@hotmail.com"};
Uri uri = Uri.parse(getExternalFilesDir(filepath)+"/"+filename);
Intent emailIntent = new Intent(Intent.ACTION_SEND);
emailIntent.putExtra(Intent.EXTRA_EMAIL, mailto);
emailIntent.putExtra(Intent.EXTRA_SUBJECT, "testing");
emailIntent.putExtra(Intent.EXTRA_TEXT, "hoooo");
emailIntent.setType("application/pdf");
emailIntent.putExtra(Intent.EXTRA_STREAM, uri);
startActivity(Intent.createChooser(emailIntent, "Send email using:"));
非常感谢任何帮助,谢谢:)
答案 0 :(得分:2)
使用此代码通过gmail共享pdf文件。
Intent email = new Intent(Intent.ACTION_SEND);
email.putExtra(Intent.EXTRA_SUBJECT, mSubjectEditText.getText().toString());
email.putExtra(Intent.EXTRA_TEXT, mBodyEditText.getText().toString());
Uri uri = Uri.parse("file://" + myFile.getAbsolutePath());
email.putExtra(Intent.EXTRA_STREAM, uri);
email.setType("message/rfc822");
startActivity(email);
答案 1 :(得分:0)
这是我通过gmail共享pdf文件的工作代码。
ArrayList<Uri> uriList = new ArrayList<Uri>();
ArrayList<String> fileNameList = new ArrayList<String>();
uriList.add(Uri.fromFile(f));
fileNameList.add(f.getName());
final Intent emailIntent = new Intent(android.content.Intent.ACTION_SEND_MULTIPLE);
emailIntent.setType("text/plain");
emailIntent.putExtra(android.content.Intent.EXTRA_EMAIL,
new String[]{""});
emailIntent.putExtra(android.content.Intent.EXTRA_CC,
new String[]{""});
emailIntent.putExtra(Intent.EXTRA_SUBJECT, "Heres the PDF you wanted!");
if (!uriList.isEmpty()) {
emailIntent.putParcelableArrayListExtra(Intent.EXTRA_STREAM, uriList);
emailIntent.putStringArrayListExtra(Intent.EXTRA_TEXT, fileNameList);
}
答案 2 :(得分:0)
秘密在乌里。
Uri imageUri = FileProvider.getUriForFile(
MainActivity.this,
"com.example.homefolder.example.provider", //(use your app signature + ".provider" )
pdfFile);
没有清单
<application>
...
<provider
android:name="android.support.v4.content.FileProvider"
android:authorities="com.example.homefolder.example.provider"
android:exported="false"
android:grantUriPermissions="true">
<!-- ressource file to create -->
<meta-data
android:name="android.support.FILE_PROVIDER_PATHS"
android:resource="@xml/file_paths">
</meta-data>
</provider>
</application>
如此
emailIntent.setType("application/pdf");
emailIntent.putExtra(Intent.EXTRA_STREAM, uri);