发送PDF文件作为邮件或提供应用程序直接查看该文件

And*_*ord 9 pdf android android-intent

我的Android 4+应用程序可以创建PDF格式的不同报告.知道我想为用户提供通过邮件发送文件或在任何可以处理PDF文件的应用程序中打开的选项.目前我使用以下代码:

Intent intent = new Intent(Intent.ACTION_SEND);
intent.setType("application/pdf");

Uri uri = Uri.parse("file://" + reportFile.getAbsolutePath());
intent.putExtra(Intent.EXTRA_STREAM, uri);

try {
    startActivity(Intent.createChooser(intent, "Share PDF file"));
} catch (Exception e) {
    Toast.makeText(ReportsActivity.this, "Error: Cannot open or share created PDF report.", Toast.LENGTH_SHORT).show();
}
Run Code Online (Sandbox Code Playgroud)

这项工作没有问题,只有"发送"应用程序可以提供,如蓝牙,谷歌驱动器,电子邮件等.我安装了Acrobat Reader应用程序,当然可以查看PDF文件.但是这个应用程序也只列出"发送签名"而不是"打开阅读器"或类似的东西.

我认为ACTION_SEND意图意味着"发送到其他应用程序"而不是严格"发送到其他地方".我可以使用什么意图包括"打开方式"选项?

Com*_*are 14

我可以使用什么意图包括"打开方式"选项?

ACTION_VIEW 用于查看文件.

startActivity(new Intent(Intent.ACTION_VIEW).setDataAndType(Uri.fromFile(reportFile), "application/pdf")));
Run Code Online (Sandbox Code Playgroud)

我认为ACTION_SEND意图意味着"发送到其他应用程序"而不是严格"发送到其他地方".

不,ACTION_SEND是送东西.这包括在某些情况下"在另一个应用中发送给自己"(例如,发送到Google云端硬盘),但它特别不适用于查看文件.