发送PDF文件作为邮件或提供应用程序来直接查看该文件 [英] Send a PDF file as Mail or offer app to directly view the file
问题描述
我的Android应用程序4+可以创建PDF格式的不同的报告。知道我想为用户提供通过邮件发送文件或可处理PDF文件的应用程序打开的选项。目前我使用下面的code:
意向意图=新意图(Intent.ACTION_SEND);
intent.setType(应用程序/ PDF格式);URI URI = Uri.parse(文件://+ reportFile.getAbsolutePath());
intent.putExtra(Intent.EXTRA_STREAM,URI);尝试{
startActivity(Intent.createChooser(意向,共享PDF文件));
}赶上(例外五){
Toast.makeText(ReportsActivity.this,错误:无法打开或共享创建的PDF报告,Toast.LENGTH_SHORT).show();
}
这workes很好,除了唯一的发送应用程序是offerd像蓝牙,谷歌驱动器,E-Mail等我安装了Acrobat Reader软件应用程序,它当然可以查看PDF文件。但是,这个程序也只列出了发送的签名,而不是与打开的读者或财产以后这样的。
我想到了 ACTION_SEND
意图将意味着发送到其他应用程序,而不是striktly送别的地方。什么意图,我可以使用,包括选项呢?
什么意图,我可以使用包括选项呢?
打开方式
块引用>
ACTION_VIEW
是查看文件。startActivity(新意图(Intent.ACTION_VIEW).setDataAndType(Uri.fromFile(reportFile),应用程序/ PDF格式)));
我以为ACTION_SEND意图将意味着发送到其他应用程序,而不是striktly送别的地方。
块引用>没有,
ACTION_SEND
是送的东西。这包括发送到自己在另一个应用程序,在某些情况下(例如,发送给谷歌驱动器),但它专门是不是查看文件。my Android 4+ app can create different reports in PDF format. Know I would like to offer the user the option to send the file via mail or to open in any app that can handle PDF files. Currently I use the following code:
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(); }
This workes fine, except only "send" apps are offerd like Bluetooth, Google Drive, E-Mail, etc. I installed the Acrobat Reader app which can of course view PDF files. But this app as well is only listed with "Send for signature" and not with "Open in Reader" or somthing like this.
I thought the
ACTION_SEND
intent would mean "send to other app" and not striktly "send somewhere else". What Intent can I use to include "open with" options as well?解决方案What Intent can I use to include "open with" options as well?
ACTION_VIEW
is for viewing files.startActivity(new Intent(Intent.ACTION_VIEW).setDataAndType(Uri.fromFile(reportFile), "application/pdf")));
I thought the ACTION_SEND intent would mean "send to other app" and not striktly "send somewhere else".
No,
ACTION_SEND
is for sending things. That includes "send to yourself in another app" in some cases (e.g., sending to Google Drive), but it specifically is not for viewing files.这篇关于发送PDF文件作为邮件或提供应用程序来直接查看该文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!