@idpass/smartscanner-capacitor 0.5.0-beta.9 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
Binary file
|
|
Binary file
|
|
@@ -4,6 +4,7 @@ import android.app.Activity
|
|
|
4
4
|
import android.content.Intent
|
|
5
5
|
import androidx.activity.result.ActivityResult
|
|
6
6
|
import com.getcapacitor.JSObject
|
|
7
|
+
import com.getcapacitor.Logger
|
|
7
8
|
import com.getcapacitor.Plugin
|
|
8
9
|
import com.getcapacitor.PluginCall
|
|
9
10
|
import com.getcapacitor.PluginMethod
|
|
@@ -21,45 +22,54 @@ class SmartScannerPlugin : Plugin() {
|
|
|
21
22
|
|
|
22
23
|
@PluginMethod
|
|
23
24
|
fun executeScanner(call: PluginCall) {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
25
|
+
try {
|
|
26
|
+
val action = call.getString("action")
|
|
27
|
+
val options: JSONObject = call.getObject("options")
|
|
28
|
+
if (action == "START_SCANNER") {
|
|
29
|
+
Timber.d("executeScanner %s", action)
|
|
30
|
+
val intent = Intent(context, SmartScannerActivity::class.java)
|
|
31
|
+
val scannerOptions = Gson().fromJson(options.toString(), ScannerOptions::class.java)
|
|
32
|
+
intent.putExtra(SmartScannerActivity.SCANNER_OPTIONS, scannerOptions)
|
|
33
|
+
startActivityForResult(call, intent, "requestScannerResult")
|
|
34
|
+
} else {
|
|
35
|
+
call.reject("\"$action\" is not a recognized action.")
|
|
36
|
+
}
|
|
37
|
+
} catch (e: Exception) {
|
|
38
|
+
call.reject(e.toString() ,e)
|
|
34
39
|
}
|
|
35
40
|
}
|
|
36
41
|
|
|
37
42
|
@ActivityCallback
|
|
38
43
|
private fun requestScannerResult(call: PluginCall, result: ActivityResult) {
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
44
|
+
try {
|
|
45
|
+
if (result.resultCode == Activity.RESULT_CANCELED) {
|
|
46
|
+
Timber.d("SmartScanner: RESULT CANCELLED")
|
|
47
|
+
call.reject("Scanning Cancelled.")
|
|
48
|
+
} else {
|
|
49
|
+
if (result.resultCode == Activity.RESULT_OK) {
|
|
50
|
+
val returnedResult = result.data?.getStringExtra(SmartScannerActivity.SCANNER_RESULT)
|
|
51
|
+
try {
|
|
52
|
+
if (returnedResult != null) {
|
|
53
|
+
Timber.d("SmartScanner: RESULT OK -- $returnedResult")
|
|
54
|
+
val scannerResult = JSONObject(returnedResult)
|
|
55
|
+
val ret = JSObject()
|
|
56
|
+
ret.put(SmartScannerActivity.SCANNER_RESULT, scannerResult)
|
|
57
|
+
call.resolve(ret)
|
|
58
|
+
} else {
|
|
59
|
+
Timber.d("SmartScanner: RESULT SCANNING NULL")
|
|
60
|
+
call.reject("Scanning result is null.")
|
|
61
|
+
}
|
|
62
|
+
} catch (e: JSONException) {
|
|
63
|
+
e.printStackTrace()
|
|
64
|
+
call.reject(e.toString() ,e)
|
|
55
65
|
}
|
|
56
|
-
}
|
|
57
|
-
|
|
66
|
+
} else {
|
|
67
|
+
Timber.d("SmartScanner: RESULT SCANNING FAILED")
|
|
68
|
+
call.reject("Scanning Failed.")
|
|
58
69
|
}
|
|
59
|
-
} else {
|
|
60
|
-
Timber.d("SmartScanner: RESULT SCANNING FAILED")
|
|
61
|
-
call.reject("Scanning Failed.")
|
|
62
70
|
}
|
|
71
|
+
} catch (e: Exception) {
|
|
72
|
+
call.reject(e.toString() ,e)
|
|
63
73
|
}
|
|
64
74
|
}
|
|
65
75
|
}
|
package/package.json
CHANGED