有没有一种方法可以使用Google文档阅读本地PDF文件?

4
我看到一种使用Google文档在线阅读PDF文件的方法... Android-加载PDF / PDF查看器 有没有办法使用它来查看存储在SD卡中的本地文件?

这是期待已久的回应...但可以尝试这个。http://androidyoungashram.blogspot.in/2011/02/read-pdf-in-android-without-third-party.html - CoDe
1个回答

0

您可以使用以下代码启动一个意图,让用户选择使用哪个应用程序打开PDF文件,这适用于任何文件和MIME类型。如果用户没有可以打开它的应用程序,则可以显示错误或执行其他必要的操作。

请注意,文件必须是全局可读的,因此如果它位于内部存储器上,则必须将其标记为全局可读,或者它必须位于外部存储器中。

private void openFile(File f, String mimeType)
{
    Intent viewIntent = new Intent();
    viewIntent.setAction(Intent.ACTION_VIEW);
    viewIntent.setDataAndType(Uri.fromFile(file), mimeType);
    // using the packagemanager to query is faster than trying startActivity
    // and catching the activity not found exception, which causes a stack unwind.
    List<ResolveInfo> resolved = getPackageManager().queryIntentActivities(viewIntent, 0);
    if(resolved != null && resolved.size() > 0)
    {
        startActivity(viewIntent);
    }
    else
    {
        // notify the user they can't open it.
    }
}

要实现这个功能,你需要编写自己的PDF解析器或使用某种第三方库。这是"Android方式"使用其他应用程序提供功能的方式:对于用户来说,打开PDF或其他文件的阅读器将感觉像是您的应用程序的一部分。 - jakebasile
WebView在iPhone上无法呈现PDF文件。我可能会采用从网络上获取的只显示一页的PDF阅读器。 - xydev
不,Android WebView 无法显示 PDF,需要使用第三方应用程序。你应该尝试我发布的方法并查看其工作原理,最终它将为用户提供比在 Android 上执行非标准操作更好、更一致的体验。 - jakebasile
1
嗯...需求总是让人头疼的。这个链接可能会有所帮助:http://ecestage.googlecode.com/svn-history/r12/branches/src/com/pdfviewer/PdfViewerActivity.java - xydev

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接