很高兴见到你。我已经看过YouTube教程和一些论坛,我正在寻找Android Studio APK的帮助。
我的apk包含在网页浏览中阅读PDF,从Android Studio安装到手机时效果非常好。但是从Play商店下载时,它不会打开任何PDF。你能帮助我吗?谢谢。
这是我的代码,在我的模拟器和我直接从Android Studio连接和安装的设备上运行时没有错误。
layout....
<?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="com.crisdanlyt.dragonesmi17.Apu">
<com.github.barteksc.pdfviewer.PDFView
android:id="@+id/pdfView"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</android.support.constraint.ConstraintLayout>
********************************************
Java
public class Apu extends AppCompatActivity {
PDFView pdfView;
ArrayAdapter<String> adapter;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_viewmnal);
PDFView pdfView = (PDFView) findViewById(R.id.pdfView);
pdfView.fromAsset("apu.pdf").load();
}
答案 0 :(得分:0)
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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=".HomeActivity">
<com.github.barteksc.pdfviewer.PDFView
android:id="@+id/pdfView"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</LinearLayout>
这是活动
public class HomeActivity extends AppCompatActivity {
private PDFView pdfView;
private void initViews() {
pdfView = (PDFView) findViewById(R.id.pdfView);
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_home);
initViews();
setPdfView();
}
public void setPdfView() {
pdfView.fromAsset("0to1.pdf")
//.pages(0, 2, 1, 3, 3, 3) // all pages are displayed by default
.enableSwipe(true) // allows to block changing pages using swipe
.swipeHorizontal(true)
.enableDoubletap(true)
.defaultPage(0)
.enableAnnotationRendering(true)
.enableAntialiasing(true)
.onDraw(new OnDrawListener() {
@Override
public void onLayerDrawn(Canvas canvas, float pageWidth, float pageHeight, int displayedPage) {
// Bitmap bitmap = Bitmap.createBitmap(canvas.getWidth(), canvas.getHeight(), Bitmap.Config.ARGB_8888); //low res
//
// Paint paint = new Paint();
// paint.setColor(Color.BLUE);
// canvas.drawBitmap(bitmap, 0,0, paint);
}
})
// allows to draw something on the current page, usually visible in the middle of the screen
//.onDraw(onDrawListener)
// allows to draw something on all pages, separately for every page. Called only for visible pages
//.onDrawAll(onDrawListener)
.onLoad(new OnLoadCompleteListener() {
@Override
public void loadComplete(int nbPages) {
//Toast.makeText(HomeActivity.this, "Complete", Toast.LENGTH_SHORT).show();
Log.d("TAG", "Complete");
}
}) // called after document is loaded and starts to be rendered
.onPageChange(new OnPageChangeListener() {
@Override
public void onPageChanged(int page, int pageCount) {
Log.d("TAG", "Complete");
}
})
.onPageScroll(new OnPageScrollListener() {
@Override
public void onPageScrolled(int page, float positionOffset) {
Log.d("TAG", "onPageScrolled");
}
})
.onError(new OnErrorListener() {
@Override
public void onError(Throwable t) {
Log.d("TAG", "onError");
}
})
.onPageError(new OnPageErrorListener() {
@Override
public void onPageError(int page, Throwable t) {
Log.d("TAG", "onPageError");
}
})
.onRender(new OnRenderListener() {
@Override
public void onInitiallyRendered(int nbPages) {
Log.d("TAG", "OnRenderListener");
}
}) // called after document is rendered for the first time
// called on single tap, return true if handled, false to toggle scroll handle visibility
.onTap(new OnTapListener() {
@Override
public boolean onTap(MotionEvent e) {
return false;
}
})
.enableAnnotationRendering(true) // render annotations (such as comments, colors or forms)
.password(null)
.scrollHandle(null)
.enableAntialiasing(true) // improve rendering a little bit on low-res screens
// spacing between pages in dp. To define spacing color, set view background
.spacing(0)
//.autoSpacing(false) // add dynamic spacing to fit each page on its own on the screen
//.linkHandler(DefaultLinkHandler)
//.pageFitPolicy(FitPolicy.WIDTH)
// .pageSnap(true) // snap pages to screen boundaries
// .pageFling(false) // make a fling change only a single page like ViewPager
.load();
}
}
创建资产文件夹并将pdf放入其中