Skip to content

Commit 7f9e61c

Browse files
Android sample application in java.
Android sample application in java - with quickcapture document scanning sdk implementation. With full help doc and technical documentation for developers for easier implementation and try.
1 parent 996fc15 commit 7f9e61c

35 files changed

Lines changed: 1072 additions & 0 deletions

java_sample/app/build.gradle

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
plugins {
2+
id 'com.android.application'
3+
}
4+
5+
android {
6+
namespace 'com.extrieve.quickcapture.docappjava'
7+
compileSdk 33
8+
9+
defaultConfig {
10+
applicationId "com.extrieve.quickcapture.docappjava"
11+
minSdk 21
12+
targetSdk 33
13+
versionCode 1
14+
versionName "1.0"
15+
16+
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
17+
}
18+
19+
buildTypes {
20+
release {
21+
minifyEnabled false
22+
proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro'
23+
}
24+
}
25+
compileOptions {
26+
sourceCompatibility JavaVersion.VERSION_1_8
27+
targetCompatibility JavaVersion.VERSION_1_8
28+
}
29+
}
30+
31+
dependencies {
32+
33+
implementation 'androidx.appcompat:appcompat:1.6.1'
34+
implementation 'com.google.android.material:material:1.5.0'
35+
implementation 'androidx.constraintlayout:constraintlayout:2.1.4'
36+
implementation 'com.extrieve.quickcapture:QCv2:2.1.2'
37+
}

java_sample/app/proguard-rules.pro

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Add project specific ProGuard rules here.
2+
# You can control the set of applied configuration files using the
3+
# proguardFiles setting in build.gradle.
4+
#
5+
# For more details, see
6+
# http://developer.android.com/guide/developing/tools/proguard.html
7+
8+
# If your project uses WebView with JS, uncomment the following
9+
# and specify the fully qualified class name to the JavaScript interface
10+
# class:
11+
#-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12+
# public *;
13+
#}
14+
15+
# Uncomment this to preserve the line number information for
16+
# debugging stack traces.
17+
#-keepattributes SourceFile,LineNumberTable
18+
19+
# If you keep the line number information, uncomment this to
20+
# hide the original source file name.
21+
#-renamesourcefileattribute SourceFile
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
package com.extrieve.quickcapture.docappjava;
2+
3+
import android.content.Context;
4+
5+
import androidx.test.platform.app.InstrumentationRegistry;
6+
import androidx.test.ext.junit.runners.AndroidJUnit4;
7+
8+
import org.junit.Test;
9+
import org.junit.runner.RunWith;
10+
11+
import static org.junit.Assert.*;
12+
13+
/**
14+
* Instrumented test, which will execute on an Android device.
15+
*
16+
* @see <a href="http://d.android.com/tools/testing">Testing documentation</a>
17+
*/
18+
@RunWith(AndroidJUnit4.class)
19+
public class ExampleInstrumentedTest {
20+
@Test
21+
public void useAppContext() {
22+
// Context of the app under test.
23+
Context appContext = InstrumentationRegistry.getInstrumentation().getTargetContext();
24+
assertEquals("com.extrieve.quickcapture.docappjava", appContext.getPackageName());
25+
}
26+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?xml version="1.0" encoding="utf-8"?>
2+
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
3+
xmlns:tools="http://schemas.android.com/tools">
4+
5+
<application
6+
android:allowBackup="true"
7+
android:dataExtractionRules="@xml/data_extraction_rules"
8+
android:fullBackupContent="@xml/backup_rules"
9+
android:icon="@mipmap/ic_launcher"
10+
android:label="@string/app_name"
11+
android:roundIcon="@mipmap/ic_launcher_round"
12+
android:supportsRtl="true"
13+
android:theme="@style/Theme.DocAppJava"
14+
tools:targetApi="31">
15+
<activity
16+
android:name=".MainActivity"
17+
android:exported="true">
18+
<intent-filter>
19+
<action android:name="android.intent.action.MAIN" />
20+
21+
<category android:name="android.intent.category.LAUNCHER" />
22+
</intent-filter>
23+
</activity>
24+
</application>
25+
26+
</manifest>
Lines changed: 192 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,192 @@
1+
package com.extrieve.quickcapture.docappjava;
2+
3+
import androidx.activity.result.ActivityResult;
4+
import androidx.activity.result.ActivityResultLauncher;
5+
import androidx.activity.result.contract.ActivityResultContracts;
6+
import androidx.annotation.NonNull;
7+
import androidx.appcompat.app.AppCompatActivity;
8+
import androidx.core.app.ActivityCompat;
9+
import androidx.core.content.ContextCompat;
10+
11+
import android.app.Activity;
12+
import android.content.ContextWrapper;
13+
import android.content.Intent;
14+
import android.content.pm.PackageManager;
15+
import android.graphics.Bitmap;
16+
import android.graphics.BitmapFactory;
17+
import android.net.Uri;
18+
import android.os.Build;
19+
import android.os.Bundle;
20+
import android.os.Environment;
21+
import android.provider.Settings;
22+
import android.util.Log;
23+
import android.widget.ImageView;
24+
import android.widget.Toast;
25+
26+
/*DEV_HELP : Import SDK from QuickCapture lib with : com.extrieve.quickcapture.sdk.**/
27+
import com.extrieve.quickcapture.sdk.*;
28+
import com.extrieve.quickcapture.sdk.CameraSupport.CamConfigClass;
29+
30+
import java.io.File;
31+
import java.io.IOException;
32+
import java.util.ArrayList;
33+
34+
public class MainActivity extends AppCompatActivity {
35+
36+
private static final int REQUEST_CODE_PERMISSIONS = 1001;
37+
/*DEV_HELP : Declare variables for the classes from SDK*/
38+
CameraHelper CameraHelper = null;
39+
ImgHelper ImageHelper = null;
40+
41+
/*DEV_HELP : Declare variables for ActivityResultLauncher to accept result from camera activity
42+
* As CameraHelper is an activity based class*/
43+
private ActivityResultLauncher<Intent> captureActivityResultLauncher;
44+
45+
46+
private final String[] REQUIRED_PERMISSIONS =
47+
new String[]{"android.permission.CAMERA"};
48+
private static final int REQUEST_CODE_FILE_RETURN = 1004;
49+
50+
ArrayList<String> FileCollection;
51+
52+
@Override
53+
protected void onCreate(Bundle savedInstanceState) {
54+
super.onCreate(savedInstanceState);
55+
setContentView(R.layout.activity_main);
56+
CheckAndPromptPermissions();
57+
58+
/*DEV_HELP : Initialise object of ImgHelper class.Pass the current activity context*/
59+
ImageHelper = new ImgHelper(this);
60+
/*DEV_HELP : Initialise object CameraHelper*/
61+
CameraHelper = new CameraHelper();
62+
63+
/*DEV_HELP : assign registerForActivityResult for getting result from CameraHelper*/
64+
captureActivityResultLauncher = registerForActivityResult(
65+
new ActivityResultContracts.StartActivityForResult(),
66+
result -> handleCaptureActivityResult(result));
67+
68+
/*DEV_HELP : Capture Document with SDK Button click handler*/
69+
findViewById(R.id.getPictureButton).setOnClickListener(v -> {
70+
SetConfig();
71+
OpenCameraActivity();
72+
});
73+
}
74+
75+
/*DEV_HELP : Basic permission for App/SDK to work*/
76+
private void CheckAndPromptPermissions() {
77+
for (String permission : REQUIRED_PERMISSIONS) {
78+
if (ContextCompat.checkSelfPermission(this, permission) != PackageManager.PERMISSION_GRANTED) {
79+
ActivityCompat.requestPermissions(this, REQUIRED_PERMISSIONS, REQUEST_CODE_PERMISSIONS);
80+
}
81+
}
82+
}
83+
84+
@Override
85+
public void onRequestPermissionsResult(int requestCode, @NonNull String[] permissions, @NonNull int[] grantResults) {
86+
super.onRequestPermissionsResult(requestCode, permissions, grantResults);
87+
if (requestCode == REQUEST_CODE_PERMISSIONS) {
88+
for (String permission : REQUIRED_PERMISSIONS) {
89+
if (ContextCompat.checkSelfPermission(this, permission) != PackageManager.PERMISSION_GRANTED) {
90+
Toast.makeText(this, "Permissions not granted by the user.", Toast.LENGTH_SHORT).show();
91+
this.finish();
92+
}
93+
//Got permission
94+
}
95+
}
96+
}
97+
98+
/*DEV_HELP : SetUp SDKConfig - Refer tech. Doc. for further info.*/
99+
private void SetConfig() {
100+
101+
ImageHelper.SetPageLayout(4);//A1-A7(1-7),PHOTO,CUSTOM,ID(8,9,10)
102+
103+
ImageHelper.SetImageQuality(1);//0,1,2 - Photo_Quality, Document_Quality, Compressed_Document
104+
105+
ImageHelper.SetDPI(200);//int dpi_val = 100, 150, 200, 300, 500, 600;
106+
107+
//can set output file path
108+
CamConfigClass.OutputPath = BuildStoragePath();
109+
}
110+
111+
/*DEV_HELP : BuildStoragePath*/
112+
private String BuildStoragePath() {
113+
ContextWrapper c = new ContextWrapper(this);
114+
String path = c.getExternalFilesDir(".GoNoGoImages").getAbsolutePath();
115+
return path;
116+
}
117+
118+
/*DEV_HELP : handleCaptureActivityResult definition*/
119+
private void handleCaptureActivityResult(ActivityResult result){
120+
{
121+
int resultCode = result.getResultCode();
122+
if (resultCode != Activity.RESULT_OK) {
123+
return;
124+
}
125+
Intent data = result.getData();
126+
Boolean Status = null;
127+
if (data != null) {
128+
Status = (Boolean) data.getExtras().get("STATUS");
129+
}
130+
String Description = (String) data.getExtras().get("DESCRIPTION");
131+
if (!Status) {
132+
String imageCaptureLog = "Description : " + Description +
133+
".Exception: " + CameraSupport.CamConfigClass.LastLogInfo;
134+
Log.d("INFO", imageCaptureLog);
135+
Toast.makeText(this, imageCaptureLog, Toast.LENGTH_LONG).show();
136+
finishActivity(REQUEST_CODE_FILE_RETURN);
137+
return;
138+
}
139+
FileCollection = (ArrayList<String>) data.getExtras().get("fileCollection");
140+
if (FileCollection == null || FileCollection.isEmpty()) return;
141+
try {
142+
showImages(FileCollection);
143+
} catch (IOException e) {
144+
e.printStackTrace();
145+
}
146+
finishActivity(REQUEST_CODE_FILE_RETURN);
147+
}
148+
}
149+
150+
/*DEV_HELP : showImages*/
151+
private void showImages(ArrayList<String> FilesPath) throws IOException {
152+
int FileCollectionLength = FilesPath.size();
153+
for (int i = 0; i < FileCollectionLength; i++) {
154+
String dir = FilesPath.get(i);
155+
File imgFile = new File(dir);
156+
//notifyMediaStoreScanner(imgFile);
157+
if (imgFile.exists()) {
158+
Bitmap myBitmap = BitmapFactory.decodeFile(imgFile.getAbsolutePath());
159+
ImageView myImage = findViewById(R.id.displayImageView);
160+
myImage.setImageBitmap(myBitmap);
161+
}
162+
Toast.makeText(this, "SDK captured " + FileCollectionLength + " images.", Toast.LENGTH_SHORT).show();
163+
}
164+
}
165+
166+
/*DEV_HELP : OpenCameraActivity*/
167+
private void OpenCameraActivity() {
168+
169+
/*DEV_HELP : Check basic permissions for camera if needed*/
170+
//if (!MainActivity.this.allPermissionsGranted()) {
171+
//Toast.makeText(MainActivity.this, "Permissions not granted by the user.", Toast.LENGTH_SHORT).show();
172+
/*DEV_HELP : TODO : handle invalid permission*/
173+
// return;
174+
// }
175+
try {
176+
/*DEV_HELP :redirecting to camera*/
177+
Intent CameraIntent = new Intent(this, Class.forName("com.extrieve.quickcapture.sdk.CameraHelper"));
178+
Uri photoURI = Uri.parse(CamConfigClass.OutputPath);
179+
this.grantUriPermission(this.getPackageName(), photoURI,
180+
Intent.FLAG_GRANT_WRITE_URI_PERMISSION | Intent.FLAG_GRANT_READ_URI_PERMISSION);
181+
if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.LOLLIPOP) {
182+
CameraIntent.addFlags(Intent.FLAG_GRANT_WRITE_URI_PERMISSION);
183+
}
184+
captureActivityResultLauncher.launch(CameraIntent);
185+
} catch (Exception ex) {
186+
/*DEV_HELP : TODO : handle invalid Exception*/
187+
Toast.makeText(this, "Failed to open camera -" + ex.getMessage(), Toast.LENGTH_LONG).show();
188+
}
189+
190+
}
191+
192+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
<vector xmlns:android="http://schemas.android.com/apk/res/android"
2+
xmlns:aapt="http://schemas.android.com/aapt"
3+
android:width="108dp"
4+
android:height="108dp"
5+
android:viewportWidth="108"
6+
android:viewportHeight="108">
7+
<path android:pathData="M31,63.928c0,0 6.4,-11 12.1,-13.1c7.2,-2.6 26,-1.4 26,-1.4l38.1,38.1L107,108.928l-32,-1L31,63.928z">
8+
<aapt:attr name="android:fillColor">
9+
<gradient
10+
android:endX="85.84757"
11+
android:endY="92.4963"
12+
android:startX="42.9492"
13+
android:startY="49.59793"
14+
android:type="linear">
15+
<item
16+
android:color="#44000000"
17+
android:offset="0.0" />
18+
<item
19+
android:color="#00000000"
20+
android:offset="1.0" />
21+
</gradient>
22+
</aapt:attr>
23+
</path>
24+
<path
25+
android:fillColor="#FFFFFF"
26+
android:fillType="nonZero"
27+
android:pathData="M65.3,45.828l3.8,-6.6c0.2,-0.4 0.1,-0.9 -0.3,-1.1c-0.4,-0.2 -0.9,-0.1 -1.1,0.3l-3.9,6.7c-6.3,-2.8 -13.4,-2.8 -19.7,0l-3.9,-6.7c-0.2,-0.4 -0.7,-0.5 -1.1,-0.3C38.8,38.328 38.7,38.828 38.9,39.228l3.8,6.6C36.2,49.428 31.7,56.028 31,63.928h46C76.3,56.028 71.8,49.428 65.3,45.828zM43.4,57.328c-0.8,0 -1.5,-0.5 -1.8,-1.2c-0.3,-0.7 -0.1,-1.5 0.4,-2.1c0.5,-0.5 1.4,-0.7 2.1,-0.4c0.7,0.3 1.2,1 1.2,1.8C45.3,56.528 44.5,57.328 43.4,57.328L43.4,57.328zM64.6,57.328c-0.8,0 -1.5,-0.5 -1.8,-1.2s-0.1,-1.5 0.4,-2.1c0.5,-0.5 1.4,-0.7 2.1,-0.4c0.7,0.3 1.2,1 1.2,1.8C66.5,56.528 65.6,57.328 64.6,57.328L64.6,57.328z"
28+
android:strokeWidth="1"
29+
android:strokeColor="#00000000" />
30+
</vector>

0 commit comments

Comments
 (0)