简体   繁体   English

在Android中阅读pdf文件

[英]Read pdf file in android

I am building an app that has function reading pdf file use ACTION_VIEW . 我正在构建一个具有读取pdf文件功能的应用程序,请使用ACTION_VIEW If device has multiple pdf reader app installed,then it will show app chooser dialog. 如果设备安装了多个pdf阅读器应用程序,则将显示应用程序选择器对话框。 So, And if there is only one pdf reader installed in device, it seems impossible to show chooser dialog. 因此,如果设备中仅安装了一个pdf阅读器,则似乎无法显示选择器对话框。

So my question is, is it possible to show chooser dialog if there is only one pdf reader installed? 所以我的问题是,如果仅安装一个pdf阅读器,是否可以显示选择器对话框?

Yes, it's possible to force a chooser even when there is exactly one Activity that will respond. 是的,即使恰好有一个活动将做出响应,也可以强制选择器 Here's some sample code demonstrating this: 以下是一些示例代码演示了这一点:

// Your original intent
Intent intent = new Intent(Intent.ACTION_VIEW);

// Configure your original intent as per usual here...

// Build a chooser intent based on your original intent
String title = getResources().getString(R.string.chooser_title);
Intent chooser = Intent.createChooser(intent, title);

// Verify the intent will resolve to at least one activity
if (intent.resolveActivity(getPackageManager()) != null) {
    startActivity(chooser);
}

No, if particular format is supported by multiple Applications then you can notify the user to choose from them but if you already configure an app as your default for particular type then you can't get chooser for that. 不可以,如果多个应用程序支持特定格式,那么您可以通知用户从中进行选择,但是如果您已经将应用程序配置为特定类型的默认格式,那么您将无法获得该选择器。 I think you want,a user to have your app as option in that chooser so you can follow this Google documentation. 我认为您希望用户在该选择器中将您的应用程序作为选项,以便您可以遵循此Google文档。

For creating non-commercial pdf app you could use MuPDF. 要创建非商业pdf应用程序,您可以使用MuPDF。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM