I have tried to read a file from the Asset. I used com.github.barteksc:android-pdf-viewer:3.1.0-beta.1 this library for displaying pdf in my app from the Asset but it shows white screen only code is here
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
binding = ActivityDisplaymantraBinding.inflate(layoutInflater)
setContentView(binding.root)
checkPdfAction(intent)
val ss: String = intent.getStringExtra("itemtext").toString()
if (ss == "್ರೀ ಗಣಾಧಿಪ ಪಂಚರತ್ನಂ"){
filename = "ganapathipancharatnam.pdf"
}
}
private fun showPdfFromAssets(pdfName: String) {
binding.mantraview.fromAsset(pdfName)
.password(null) // if password protected, then write password
.defaultPage(0) // set the default page to open
.enableSwipe(true)
.enableAntialiasing(true)
.nightMode(true)
.onPageError { page, _ ->
Toast.makeText(
this,
"Error at page: $page", Toast.LENGTH_LONG
).show()
}
.load()
}
private fun checkPdfAction(intent: Intent?) {
when (intent?.getStringExtra("ViewType")) {
"assets" -> showPdfFromAssets(this.filename)
}
}
}
I don't known why its shows only white screen. XML FIle
<com.github.barteksc.pdfviewer.PDFView
android:id="@+id/mantraview"
android:layout_width="match_parent"
android:layout_height="match_parent"
/>
<ProgressBar
android:id="@+id/progressBar"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:visibility="gone"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="@+id/mantraview" />