Code Monkey home page Code Monkey logo

phonescanner's Introduction

PhoneScanner

Use your Android smartphone as document scanner

We use the library from https://github.com/jhansireddy/AndroidScannerDemo to scan documents using the smartphone camera.

AndroidScannerDemo seems quite abandoned and no longer maintained. I built up this project to provide a working solution.

Steps to integrate AndroidScannerDemo in your project

  • git clone https://github.com/jhansireddy/AndroidScannerDemo.git into a standalone dir;
  • Create or using your project: File -> New -> Import module...;
  • As source directory point to: ~/_dirWhereYouClonedAndroidScannerDemo_/AndroidScannerDemo/ScanDemoExample/scanlibrary and confirm;
  • In Android Studio left tree, be sure to visualize project as Android view; right click on main app and on popupmenu choose Open module settings... or hit F4;
  • Choose Dependencies and add Scanlibrary; hit Apply to make a gradle syncronization and Ok when finished;

At this point all the lack of updates of AndroidScannerDemo is shown; update as suggested taking a look at my example project, on AndroidManifest.xml and on build.gradle of scanlibrary module.

Now everything should compile and works correctly.

Issues I've found

AndroidManifest.xml merging errors on fileprovider I created a derived FileProvider class as below:

import androidx.core.content.FileProvider

class MyFileProvider: FileProvider() {
}

and on my app manifest:

...
        <provider
            android:name=".MyFileProvider"
            android:authorities="${applicationId}.fileprovider"
            android:exported="false"
            android:grantUriPermissions="true"
            tools:replace="android:authorities">
            <meta-data
                android:name="android.support.FILE_PROVIDER_PATHS"
                android:resource="@xml/filepaths" />
        </provider>
...

I know that this solution is not the best but if anyone has a better one, please suggest!

How to use the library

On the activity / fragment class:

Start a scanning:

    private val DOCUMENT_SCAN = 20
        
    ...
        
    scanDocument.setOnClickListener {
        val intent = Intent(applicationContext, ScanActivity::class.java)
        intent.putExtra(ScanConstants.OPEN_INTENT_PREFERENCE, ScanConstants.OPEN_CAMERA)
        startActivityForResult(intent, DOCUMENT_SCAN)
    }

...and to catch the result:

    override fun onActivityResult(requestCode: Int, resultCode: Int, data: Intent?) {
        super.onActivityResult(requestCode, resultCode, data)

        if (resultCode != Activity.RESULT_OK) {
            return
        }

        when(requestCode) {
            DOCUMENT_SCAN -> {
                val uri: Uri = data?.extras?.getParcelable(ScanConstants.SCANNED_RESULT)!!
                var bitmap: Bitmap? = null
                try {
                    bitmap = MediaStore.Images.Media.getBitmap(contentResolver, uri)
                    contentResolver.delete(uri, null, null)
                    imagePost.setImageBitmap(bitmap)
                } catch (e: IOException) {
                    e.printStackTrace()
                }
            }
        }
    }

At this stage on bitmap you get an adjusted usable image.

phonescanner's People

Contributors

fpiraneo avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.