B4A Library [class] DocumentScanner based on Google ML Kit

This class allows using ML Kit to scan documents: https://developers.google.com/ml-kit/vision/doc-scanner

1713362813439.png


It requires some configuration:

1. Open B4A Sdk Manager. Search for mlkit and install all items.
2. Main module:
B4X:
#AdditionalJar: com.google.android.gms:play-services-mlkit-document-scanner
#AdditionalJar: kotlin-stdlib-1.6.10
#AdditionalJar: androidx.arch.core:core-runtime
3. Manifest editor:
B4X:
CreateResourceFromFile(Macro, FirebaseAnalytics.GooglePlayBase) 'add if not already there
'*********  ML kit **********
AddApplicationText(
 <activity
            android:name="com.google.mlkit.vision.documentscanner.internal.GmsDocumentScanningDelegateActivity"
            android:exported="false"
            android:screenOrientation="portrait"
            android:theme="@android:style/Theme.Black.NoTitleBar.Fullscreen"
             >
        </activity>
         <provider
            android:name="com.google.mlkit.common.internal.MlKitInitProvider"
            android:authorities="${applicationId}.mlkitinitprovider"
            android:exported="false"
            android:initOrder="99" />

        <service
            android:name="com.google.mlkit.common.internal.MlKitComponentDiscoveryService"
            android:directBootAware="true"
            android:exported="false"
             >
            <meta-data
                android:name="com.google.firebase.components:com.google.mlkit.common.internal.CommonComponentRegistrar"
                android:value="com.google.firebase.components.ComponentRegistrar" />
        </service>
)
'******************************

Usage is simple. You call scan, the scanning UI appears, after the user scans you get a list of image uris that are loaded using the special "ContentDir" virtual folder.
See the attached example. The class is inside.
This is a B4A only class.
 

Attachments

  • DocumentScanner.zip
    15.7 KB · Views: 64

fredo

Well-Known Member
Licensed User
Longtime User
This seems very useful.

However, I encounter an error during compilation:

B4X:
Organizing libraries.
Error Maven artifact not found:
com.google.mlkit/common Source: com.google.android.gms:play-services-mlkit-document-scanner
The artifact was installed via the SDK Manager and the IDE was restarted afterwards.
18-04-2024_16-14-02.png

Also, the `kotlin-stdlib-1.6.10` was not found in the SDK Manager.

What would be the next logical step on my part?
 

ThePlankton

Member
Licensed User
This seems very useful.

However, I encounter an error during compilation:

B4X:
Organizing libraries.
Error Maven artifact not found:
com.google.mlkit/common Source: com.google.android.gms:play-services-mlkit-document-scanner
The artifact was installed via the SDK Manager and the IDE was restarted afterwards.
View attachment 152810

Also, the `kotlin-stdlib-1.6.10` was not found in the SDK Manager.

What would be the next logical step on my part?
Were you able to solve this? I'm having the same issue (Error Maven artifact not found)
 
Top