我试图从Firebase存储器中下载PDF文件,然后我想查看pdf文件,我已使用此代码下载了该文件:
private void downloadToLocalFile(StorageReference fileRef) {
if (fileRef != null) {
try {
final File localFile = File.createTempFile("lessons" ,"pdf");
fileRef.getFile(localFile).addOnSuccessListener(new OnSuccessListener<FileDownloadTask.TaskSnapshot>() {
@Override
public void onSuccess(FileDownloadTask.TaskSnapshot taskSnapshot) {
Log.e("MAS_FILE" , localFile.getAbsolutePath()+"");
}
}).addOnFailureListener(new OnFailureListener() {
@Override
public void onFailure(@NonNull Exception exception) {
}
}).addOnProgressListener(new OnProgressListener<FileDownloadTask.TaskSnapshot>() {
@Override
public void onProgress(FileDownloadTask.TaskSnapshot taskSnapshot) {
// progress percentage
double progress = (100.0 * taskSnapshot.getBytesTransferred()) / taskSnapshot.getTotalByteCount();
Log.e("MAS_Progress", "Downloaded " + ((int) progress) + "%...");
}
});
} catch (IOException e) {
e.printStackTrace();
}
} else {
Toast.makeText(getApplicationContext(), "Upload file before downloading", Toast.LENGTH_LONG).show();
}
}
然后我已使用该库查看该pdf
implementation 'com.github.barteksc:android-pdf-viewer:3.2.0-beta.1'
<com.github.barteksc.pdfviewer.PDFView
android:id="@+id/pdfView"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
这是库链接: https://github.com/barteksc/AndroidPdfViewer
那么我如何获得下载的文件以使用PDFView查看?