1

我是安卓和开发世界的新手。我需要帮助来解决这个问题。(场景如下)

我使用 HTML5 和 CSS 创建了一个 Android 应用程序,并使用 phonegap 将其捆绑在一起。现在我需要在这个应用程序中显示 PDF 文件,并为用户提供两个选项,无论是第一次下载然后阅读还是第二次在线阅读

所以我的问题是,我无法在应用程序中显示 PDF。我怎么能做到这一点?请帮忙 。我正在尝试从过去 4 天开始解决它,并尝试了论坛中已经给出的每个解决方案,但仍然没有成功。

如果有人一步一步的程序或一个例子来参考,那对我来说会很棒。

谢谢你 Minal

4

3 回答 3

0

这可能会有所帮助:如何通过 Intent 从 SD 卡打开 PDF

基本想法是让一个 pdf 应用程序为您呈现 pdf,而您的应用程序只是启动了这样做的意图。

于 2013-06-04T10:23:06.103 回答
0

你可以通过这样的意图打开pdf文件

File file = new File(Environment.getExternalStorageDirectory().getAbsolutePath()+"/example.pdf"); Intent intent = new Intent(Intent.ACTION_VIEW); intent.setDataAndType(Uri.fromFile(file),”application/pdf”); intent.setFlags(Intent.FLAG_ACTIVITY_NO_HISTORY); startActivity(intent);

于 2013-06-04T10:32:38.757 回答
0

试试这个代码

private void openBook() {
    File file = new File(mRealPath);
    Uri path = Uri.fromFile(file);
    Intent intent = new Intent(Intent.ACTION_VIEW);
    intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
    intent.setDataAndType(path, getString(R.string.application_type));
    try {
        startActivity(intent);
    } catch (ActivityNotFoundException e) {
        Toast.makeText(FirstTab.this, 
                getString(R.string.no_application_found), 
                Toast.LENGTH_SHORT).show();
    }
}
于 2013-06-04T10:25:35.920 回答