17
17
import org .json .JSONException ;
18
18
import org .json .JSONObject ;
19
19
20
+ import java .io .File ;
20
21
import java .io .IOException ;
21
22
import java .util .HashMap ;
22
23
23
24
import io .anyline2 .WrapperConfig ;
24
25
import io .anyline2 .WrapperInfo ;
25
26
import io .anyline2 .core .ScanController ;
27
+ import io .anyline2 .di .context .ContextProvider ;
26
28
import io .anyline2 .legacy .products .AnylineUpdater ;
27
29
import io .anyline2 .legacy .trainer .AssetContext ;
28
30
import io .anyline2 .AnylineSdk ;
32
34
33
35
class AnylineSDKPlugin extends ReactContextBaseJavaModule implements ResultReporter .OnResultListener {
34
36
37
+ static {
38
+ System .loadLibrary ("opencv_java3_al" );
39
+ System .loadLibrary ("anylineCore" );
40
+ }
41
+
35
42
public static final String REACT_CLASS = "AnylineSDKPlugin" ;
36
43
public static final String EXTRA_LICENSE_KEY = "EXTRA_LICENSE_KEY" ;
37
44
public static final String EXTRA_CONFIG_JSON = "EXTRA_CONFIG_JSON" ;
@@ -63,6 +70,7 @@ class AnylineSDKPlugin extends ReactContextBaseJavaModule implements ResultRepor
63
70
super (context );
64
71
this .reactContext = context ;
65
72
this .assetContextJsonParser = new AssetContextJsonParser ();
73
+ ContextProvider .setInstance (context );
66
74
}
67
75
68
76
@ Override
@@ -232,6 +240,35 @@ public void exportCachedEvents(final Promise promise) {
232
240
}
233
241
}
234
242
243
+ /**
244
+ * This function removes all previous scan result images from disk, either from external
245
+ * or internal files dir, e.g.:
246
+ * /sdcard/Android/[applicationId]/files/results/image1729849635965
247
+ */
248
+ private void deleteAllPreviousScanResultImages () {
249
+ String imagePath = "" ;
250
+ if (reactContext .getExternalFilesDir (null ) != null ) {
251
+ imagePath = reactContext
252
+ .getExternalFilesDir (null )
253
+ .toString () + "/results/" ;
254
+
255
+ } else if (reactContext .getFilesDir () != null ) {
256
+ imagePath = reactContext
257
+ .getFilesDir ()
258
+ .toString () + "/results/" ;
259
+ }
260
+
261
+ File resultFolder = new File (imagePath );
262
+ File [] files = resultFolder .listFiles ();
263
+ if (files != null ) {
264
+ for (int fileIndex = 0 ; fileIndex < files .length ; fileIndex ++) {
265
+ if (files [fileIndex ].getName ().startsWith ("image" )) {
266
+ files [fileIndex ].delete ();
267
+ }
268
+ }
269
+ }
270
+ }
271
+
235
272
@ ReactMethod
236
273
public void setupPromise (String config , String scanMode , final Promise promise ) {
237
274
setupPromiseWithInitializationParameters (null , config , scanMode , promise );
@@ -243,6 +280,7 @@ public void setupPromiseWithInitializationParameters(String initializationParame
243
280
this .config = config ;
244
281
this .scanViewInitializationParameters = initializationParameters ;
245
282
283
+ deleteAllPreviousScanResultImages ();
246
284
routeScanMode (scanMode );
247
285
}
248
286
0 commit comments