Awesome
PDF-Doc-Scan
Android PDF document scanning app
Main point of this app is to scan or select existing PDF documents simply using intent or chooser. Other apps require payment to access their api/sdk or simply don't have a possible way to do it. So they rely on switching between an app ,file chooser and a scanner.
Usage Example
Create ActivityResultLauncher
val pdfResultLauncher = registerForActivityResult(StartActivityForResult()) {
val uri = it.data?.data
if (it.resultCode == Activity.RESULT_OK && uri != null) {
// context.contentResolver.openInputStream(uri)
}
}
Or using Compose
val pdfResultLauncher = rememberLauncherForActivityResult(contract = StartActivityForResult()){
val uri = it.data?.data
if (it.resultCode == Activity.RESULT_OK && uri != null) {
// context.contentResolver.openInputStream(uri)
}
}
If you target Android 11 (API level 30) and up add query to your AndroidManifest.xml to make it visible for your app.
<queries>
<package android:name="com.littletrickster.scanner" />
</queries>
Query and launch directly
val intent = Intent()
intent.component = ComponentName("com.littletrickster.scanner", "com.littletrickster.scanner.ScanActivity")
intent.action = Intent.ACTION_PICK
intent.type = "application/pdf"
val pdfInfo = context.packageManager.queryIntentActivities(intent, 0)
if (pdfInfo.firstOrNull()?.activityInfo?.enabled == true) {
pdfResultLauncher.launch(intent)
}
Comments
Made this as a prototype while learning Compose framework in late 2021