Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/EmptyTag/163.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/kotlin/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 无法在我的应用程序中使用barteksc PDF查看器_Android - Fatal编程技术网

Android 无法在我的应用程序中使用barteksc PDF查看器

Android 无法在我的应用程序中使用barteksc PDF查看器,android,Android,我尝试使用[bartecksc AndroidPdfViewer][1] [1] :在我的android应用程序中,查看应用程序内资产文件夹中的PDF文件,但它不起作用。它显示一个空白屏幕。 以下是我所做的: 我在build.gradle文件中添加了这个依赖项 implementation 'com.github.barteksc:android-pdf-viewer:3.1.0-beta.1' (我甚至试过使用实现'com.github.barteksc:android pdf查看器:2.8

我尝试使用[bartecksc AndroidPdfViewer][1]

[1] :在我的android应用程序中,查看应用程序内资产文件夹中的PDF文件,但它不起作用。它显示一个空白屏幕。 以下是我所做的: 我在build.gradle文件中添加了这个依赖项

implementation 'com.github.barteksc:android-pdf-viewer:3.1.0-beta.1'
(我甚至试过使用
实现'com.github.barteksc:android pdf查看器:2.8.2'

我在activity_main.xml中添加了以下小部件

<com.github.barteksc.pdfviewer.PDFView
        android:id="@+id/pdfView"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent" />
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity">

    <com.github.barteksc.pdfviewer.PDFView
        android:id="@+id/pdfView"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent" />

</android.support.constraint.ConstraintLayout>
我想显示的文件位于资产文件夹中,名为sample_file.pdf

以下是我的MainActivity.java

package com.umersoftwares.bartekscpdfview;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;

import com.github.barteksc.pdfviewer.PDFView;

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        PDFView pdfView=findViewById(R.id.pdfView);
        pdfView.fromAsset("sample_file.pdf");
    }
}
以下是我的活动_main.xml

<com.github.barteksc.pdfviewer.PDFView
        android:id="@+id/pdfView"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent" />
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity">

    <com.github.barteksc.pdfviewer.PDFView
        android:id="@+id/pdfView"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent" />

</android.support.constraint.ConstraintLayout>

您发布的代码缺少读取存储所需的权限

在github上有一个你发布的库的演示。检查请求读取存储权限的代码,并在代码中实现它

您可以参考随库提供的演示示例类


问题是需要调用PDFView对象上的
.load()
方法来显示pdf。因此,在java文件中,应该是这样的

pdfView.fromAsset("sample_file.pdf")
.load();
而不仅仅是:

pdfView.fromAsset("sample_file.pdf");