@regulaforensics/cordova-plugin-document-reader-api 6.5.0 → 6.6.1
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.
- package/example/config.xml +7 -0
- package/example/package.json +2 -2
- package/example/www/index.html +109 -111
- package/example/www/js/index.js +17 -6
- package/package.json +1 -1
- package/plugin.xml +5 -3
- package/src/android/BluetoothUtil.kt +108 -0
- package/src/android/DocumentReader.java +268 -11
- package/src/android/Helpers.java +6 -5
- package/src/android/JSONConstructor.java +154 -1341
- package/src/android/RegulaConfig.java +22 -1
- package/src/android/build.gradle +7 -11
- package/src/ios/RGLDocumentReader.m +204 -26
- package/src/ios/RGLWJSONConstructor.h +6 -0
- package/src/ios/RGLWJSONConstructor.m +102 -1
- package/src/ios/RegulaConfig.m +25 -1
- package/www/DocumentReader.js +115 -204
- package/example/www/certificates/icaopkd-002-ml-000131.ldif +0 -40593
- package/tmp.64209.json +0 -30
package/example/config.xml
CHANGED
|
@@ -17,11 +17,18 @@
|
|
|
17
17
|
<allow-intent href="mailto:*" />
|
|
18
18
|
<allow-intent href="geo:*" />
|
|
19
19
|
<platform name="android">
|
|
20
|
+
<preference name="GradlePluginKotlinEnabled" value="true" />
|
|
21
|
+
<preference name="GradlePluginKotlinCodeStyle" value="official" />
|
|
22
|
+
<preference name="GradlePluginKotlinVersion" value="1.7.10" />
|
|
23
|
+
<preference name="android-minSdkVersion" value="21" />
|
|
24
|
+
<preference name="android-targetSdkVersion" value="33" />
|
|
20
25
|
<preference name="AndroidXEnabled" value="true" />
|
|
21
26
|
<allow-intent href="market:*" />
|
|
22
27
|
<config-file parent="/*" target="AndroidManifest.xml">
|
|
23
28
|
<uses-permission android:name="android.permission.NFC" />
|
|
24
29
|
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
|
|
30
|
+
<uses-permission android:name="android.permission.BLUETOOTH_CONNECT" />
|
|
31
|
+
<uses-permission android:name="android.permission.BLUETOOTH_SCAN" />
|
|
25
32
|
</config-file>
|
|
26
33
|
</platform>
|
|
27
34
|
<platform name="ios">
|
package/example/package.json
CHANGED
|
@@ -16,8 +16,8 @@
|
|
|
16
16
|
"cordova-android": "^10.1.1",
|
|
17
17
|
"cordova-ios": "^6.2.0",
|
|
18
18
|
"cordova-plugin-add-swift-support": "^2.0.2",
|
|
19
|
-
"@regulaforensics/cordova-plugin-document-reader-api": "6.
|
|
20
|
-
"@regulaforensics/cordova-plugin-document-reader-core-fullrfid": "6.
|
|
19
|
+
"@regulaforensics/cordova-plugin-document-reader-api": "6.6.1",
|
|
20
|
+
"@regulaforensics/cordova-plugin-document-reader-core-fullrfid": "6.6.0",
|
|
21
21
|
"cordova-plugin-file": "^6.0.2",
|
|
22
22
|
"cordova-plugin-image-picker": "^1.1.3",
|
|
23
23
|
"cordova-plugin-android-permissions": "1.1.0",
|
package/example/www/index.html
CHANGED
|
@@ -1,115 +1,113 @@
|
|
|
1
1
|
<!DOCTYPE html>
|
|
2
2
|
<html>
|
|
3
|
-
|
|
4
|
-
<
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
<
|
|
15
|
-
<div
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
</div>
|
|
23
|
-
</div>
|
|
24
|
-
<div id="mainUI" style="
|
|
25
|
-
text-align: center;
|
|
26
|
-
background-color: #F5FCFF;
|
|
27
|
-
height: 100%;">
|
|
28
|
-
<div id="deviceready" style="position: absolute; top: 10px; width: 100%; text-align: center;">
|
|
29
|
-
<p class="event listening">Connecting to Device</p>
|
|
30
|
-
<p id="status" class="event received">Ready</p>
|
|
31
|
-
</div>
|
|
32
|
-
<div style="padding: 5px">
|
|
33
|
-
<div style="align-items:center; text-align: center;display: inline-block;"><br><br>
|
|
34
|
-
<p style="margin-bottom: 5px">Portrait</p>
|
|
35
|
-
<img style="height: 133px; width: 100px" src="img/portrait.png" resizeMode="contain"
|
|
36
|
-
id="portraitImage"/>
|
|
3
|
+
<head>
|
|
4
|
+
<meta http-equiv="Content-Security-Policy"
|
|
5
|
+
content="default-src 'self' data: gap: https://ssl.gstatic.com 'unsafe-eval'; style-src 'self' 'unsafe-inline'; media-src *; img-src 'self' data: content:;">
|
|
6
|
+
<meta name="format-detection" content="telephone=no">
|
|
7
|
+
<meta name="msapplication-tap-highlight" content="no">
|
|
8
|
+
<meta name="viewport" content="initial-scale=1, width=device-width, viewport-fit=cover">
|
|
9
|
+
<link rel="stylesheet" type="text/css" href="css/index.css">
|
|
10
|
+
<title>Document Reader</title>
|
|
11
|
+
</head>
|
|
12
|
+
|
|
13
|
+
<body>
|
|
14
|
+
<div id="rfidUI" style="text-align: center; background-color: #F5FCFF; height: 100%; width:100%; display: none;">
|
|
15
|
+
<div style="position: absolute; top: 50%; left: 50%; width:100%; -ms-transform: translate(-50%, -50%); transform: translate(-50%, -50%); ">
|
|
16
|
+
<p id="rfidUIHeader">Reading RFID</p>
|
|
17
|
+
<p id="rfidDescription">Place your phone on top of the NFC tag</p>
|
|
18
|
+
<progress id="rfidProgress" value="0" max="100"></progress>
|
|
19
|
+
<br><br><br>
|
|
20
|
+
<button id="cancelButton">X</button>
|
|
21
|
+
</div>
|
|
37
22
|
</div>
|
|
38
|
-
<div style="align
|
|
39
|
-
<
|
|
40
|
-
|
|
23
|
+
<div id="mainUI" style="text-align: center;background-color: #F5FCFF;height: 100%;">
|
|
24
|
+
<div style="padding: 5px">
|
|
25
|
+
<div id="deviceready" style="padding-top: 12px; width: 100%; text-align: center;">
|
|
26
|
+
<p class="event listening">Connecting to Device</p>
|
|
27
|
+
<p id="status" class="event received">Ready</p>
|
|
28
|
+
</div>
|
|
29
|
+
<div style="align-items:center; text-align: center;display: inline-block;"><br><br>
|
|
30
|
+
<p style="margin-bottom: 5px">Portrait</p>
|
|
31
|
+
<img style="height: 133px; width: 100px" src="img/portrait.png" resizeMode="contain"
|
|
32
|
+
id="portraitImage"/>
|
|
33
|
+
</div>
|
|
34
|
+
<div style="align-items: center; text-align: center; display: inline-block;"><br><br>
|
|
35
|
+
<p style="margin-bottom: 5px">Document</p>
|
|
36
|
+
<img style="height: 133px;" src="img/id.png" resizeMode="contain" id="documentImage"/>
|
|
37
|
+
</div>
|
|
38
|
+
</div>
|
|
39
|
+
|
|
40
|
+
<div>
|
|
41
|
+
<div id="scenariosRadioGroup"
|
|
42
|
+
style="position: absolute; bottom: 130px; top: 300px; left: 75px; width:225px; padding: 5px; text-align:left; overflow: auto"/>
|
|
43
|
+
</div>
|
|
44
|
+
|
|
45
|
+
<div style="position: absolute; bottom: 0px; width: 100%;">
|
|
46
|
+
<div id="rfidDiv" style="flex-direction: row; padding: 5px">
|
|
47
|
+
<input id="rfidCheckbox" type="checkbox" name="rfid" disabled><span
|
|
48
|
+
id="rfidCheckboxText"
|
|
49
|
+
style="color: lightgrey"> Process rfid reading(unavailable)</span><br>
|
|
50
|
+
</div>
|
|
51
|
+
<div id="encryptionDiv" style="flex-direction: row; padding: 5px">
|
|
52
|
+
<input id="encryptionCheckbox" type="checkbox" name="rfid" disabled><span
|
|
53
|
+
id="encryptionCheckboxText"
|
|
54
|
+
style="color: lightgrey"> Data encryption(unavailable)</span><br>
|
|
55
|
+
</div>
|
|
56
|
+
<div style="flex-direction: row; padding: 10px">
|
|
57
|
+
<button id="showScannerButton" style="margin-right: 20px">scan doc</button>
|
|
58
|
+
<button id="showImagePicker" style="margin-left: 20px">scan image</button>
|
|
59
|
+
</div>
|
|
60
|
+
</div>
|
|
41
61
|
</div>
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
}
|
|
95
|
-
|
|
96
|
-
button:hover {
|
|
97
|
-
background: -webkit-gradient(linear, left top, left bottom, color-stop(0.05, #0688fa), color-stop(1, #2dabf9));
|
|
98
|
-
background: -moz-linear-gradient(top, #0688fa 5%, #2dabf9 100%);
|
|
99
|
-
background: -webkit-linear-gradient(top, #0688fa 5%, #2dabf9 100%);
|
|
100
|
-
background: -o-linear-gradient(top, #0688fa 5%, #2dabf9 100%);
|
|
101
|
-
background: -ms-linear-gradient(top, #0688fa 5%, #2dabf9 100%);
|
|
102
|
-
background: linear-gradient(to bottom, #0688fa 5%, #2dabf9 100%);
|
|
103
|
-
filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#0688fa', endColorstr='#2dabf9', GradientType=0);
|
|
104
|
-
background-color: #0688fa;
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
button:active {
|
|
108
|
-
position: relative;
|
|
109
|
-
top: 1px;
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
</style>
|
|
113
|
-
</body>
|
|
114
|
-
|
|
115
|
-
</html>
|
|
62
|
+
|
|
63
|
+
<script type="text/javascript" src="cordova.js"></script>
|
|
64
|
+
<script type="text/javascript" src="js/index.js"></script>
|
|
65
|
+
|
|
66
|
+
<style type="text/css">
|
|
67
|
+
button {
|
|
68
|
+
width: 40%;
|
|
69
|
+
-moz-box-shadow: inset 0px -3px 7px 0px #29bbff;
|
|
70
|
+
-webkit-box-shadow: inset 0px -3px 7px 0px #29bbff;
|
|
71
|
+
box-shadow: inset 0px -3px 7px 0px #29bbff;
|
|
72
|
+
background: -webkit-gradient(linear, left top, left bottom, color-stop(0.05, #2dabf9), color-stop(1, #0688fa));
|
|
73
|
+
background: -moz-linear-gradient(top, #2dabf9 5%, #0688fa 100%);
|
|
74
|
+
background: -webkit-linear-gradient(top, #2dabf9 5%, #0688fa 100%);
|
|
75
|
+
background: -o-linear-gradient(top, #2dabf9 5%, #0688fa 100%);
|
|
76
|
+
background: -ms-linear-gradient(top, #2dabf9 5%, #0688fa 100%);
|
|
77
|
+
background: linear-gradient(to bottom, #2dabf9 5%, #0688fa 100%);
|
|
78
|
+
filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#2dabf9', endColorstr='#0688fa', GradientType=0);
|
|
79
|
+
background-color: #2dabf9;
|
|
80
|
+
-moz-border-radius: 3px;
|
|
81
|
+
-webkit-border-radius: 3px;
|
|
82
|
+
border-radius: 3px;
|
|
83
|
+
border: 1px solid #0b0e07;
|
|
84
|
+
display: inline-block;
|
|
85
|
+
cursor: pointer;
|
|
86
|
+
color: #ffffff;
|
|
87
|
+
font-family: Arial;
|
|
88
|
+
font-size: 15px;
|
|
89
|
+
padding: 9px 23px;
|
|
90
|
+
text-decoration: none;
|
|
91
|
+
text-shadow: 0px 1px 0px #263666;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
button:hover {
|
|
95
|
+
background: -webkit-gradient(linear, left top, left bottom, color-stop(0.05, #0688fa), color-stop(1, #2dabf9));
|
|
96
|
+
background: -moz-linear-gradient(top, #0688fa 5%, #2dabf9 100%);
|
|
97
|
+
background: -webkit-linear-gradient(top, #0688fa 5%, #2dabf9 100%);
|
|
98
|
+
background: -o-linear-gradient(top, #0688fa 5%, #2dabf9 100%);
|
|
99
|
+
background: -ms-linear-gradient(top, #0688fa 5%, #2dabf9 100%);
|
|
100
|
+
background: linear-gradient(to bottom, #0688fa 5%, #2dabf9 100%);
|
|
101
|
+
filter: progid:DXImageTransform.Microsoft.gradient(startColorstr='#0688fa', endColorstr='#2dabf9', GradientType=0);
|
|
102
|
+
background-color: #0688fa;
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
button:active {
|
|
106
|
+
position: relative;
|
|
107
|
+
top: 1px;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
</style>
|
|
111
|
+
</body>
|
|
112
|
+
|
|
113
|
+
</html>
|
package/example/www/js/index.js
CHANGED
|
@@ -242,12 +242,23 @@ var app = {
|
|
|
242
242
|
}
|
|
243
243
|
|
|
244
244
|
function displayResults(results) {
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
document.getElementById("
|
|
249
|
-
|
|
250
|
-
|
|
245
|
+
if(results == null) return
|
|
246
|
+
|
|
247
|
+
DocumentReader.getTextFieldValueByType(results, Enum.eVisualFieldType.FT_SURNAME_AND_GIVEN_NAMES, function (value) {
|
|
248
|
+
document.getElementById("status").style.backgroundColor = "green"
|
|
249
|
+
document.getElementById("status").innerHTML = value
|
|
250
|
+
this.setState({ fullName: value })
|
|
251
|
+
}, function (error) { console.log(error) })
|
|
252
|
+
|
|
253
|
+
DocumentReader.getGraphicFieldImageByType(results, Enum.eGraphicFieldType.GF_DOCUMENT_IMAGE, function (value) {
|
|
254
|
+
if(value != null)
|
|
255
|
+
document.getElementById("documentImage").src = "data:image/png;base64," + value
|
|
256
|
+
}, function (error) { console.log(error) })
|
|
257
|
+
|
|
258
|
+
DocumentReader.getGraphicFieldImageByType(results, Enum.eGraphicFieldType.GF_PORTRAIT, function (value) {
|
|
259
|
+
if(value != null)
|
|
260
|
+
document.getElementById("portraitImage").src = "data:image/png;base64," + value
|
|
261
|
+
}, function (error) { console.log(error) })
|
|
251
262
|
}
|
|
252
263
|
|
|
253
264
|
function clearResults() {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@regulaforensics/cordova-plugin-document-reader-api",
|
|
3
|
-
"version": "6.
|
|
3
|
+
"version": "6.6.1",
|
|
4
4
|
"description": "Cordova plugin for reading and validation of identification documents (API framework)",
|
|
5
5
|
"cordova": {
|
|
6
6
|
"id": "@regulaforensics/cordova-plugin-document-reader-api",
|
package/plugin.xml
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
<?xml version='1.0' encoding='utf-8'?>
|
|
2
|
-
<plugin id="cordova-plugin-document-reader-api" version="6.
|
|
2
|
+
<plugin id="cordova-plugin-document-reader-api" version="6.6.1"
|
|
3
3
|
xmlns="http://apache.org/cordova/ns/plugins/1.0">
|
|
4
4
|
<name>DocumentReaderApi</name>
|
|
5
5
|
<description>Cordova plugin Document reader api</description>
|
|
@@ -23,9 +23,10 @@
|
|
|
23
23
|
<header-file src="src/ios/RegulaConfig.h" />
|
|
24
24
|
<source-file src="src/ios/RegulaConfig.m" />
|
|
25
25
|
<podspec>
|
|
26
|
-
|
|
26
|
+
<config>
|
|
27
|
+
</config>
|
|
27
28
|
<pods>
|
|
28
|
-
<pod name="DocumentReader" spec="~> 6.
|
|
29
|
+
<pod name="DocumentReader" spec="~> 6.6.2753" />
|
|
29
30
|
</pods>
|
|
30
31
|
</podspec>
|
|
31
32
|
</platform>
|
|
@@ -41,5 +42,6 @@
|
|
|
41
42
|
<source-file src="src/android/JSONConstructor.java" target-dir="src/cordova.plugin.documentreader" />
|
|
42
43
|
<source-file src="src/android/RegulaConfig.java" target-dir="src/cordova.plugin.documentreader" />
|
|
43
44
|
<source-file src="src/android/Helpers.java" target-dir="src/cordova.plugin.documentreader" />
|
|
45
|
+
<source-file src="src/android/BluetoothUtil.kt" target-dir="java/cordova.plugin.documentreader" />
|
|
44
46
|
</platform>
|
|
45
47
|
</plugin>
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
package cordova.plugin.documentreader
|
|
2
|
+
|
|
3
|
+
import android.Manifest.permission.*
|
|
4
|
+
import android.annotation.SuppressLint
|
|
5
|
+
import android.app.Activity
|
|
6
|
+
import android.bluetooth.BluetoothAdapter
|
|
7
|
+
import android.content.ComponentName
|
|
8
|
+
import android.content.Intent
|
|
9
|
+
import android.content.ServiceConnection
|
|
10
|
+
import android.content.pm.PackageManager.PERMISSION_GRANTED
|
|
11
|
+
import android.os.Build
|
|
12
|
+
import android.os.IBinder
|
|
13
|
+
import android.provider.Settings
|
|
14
|
+
import androidx.annotation.RequiresPermission
|
|
15
|
+
import androidx.core.app.ActivityCompat.requestPermissions
|
|
16
|
+
import androidx.core.content.ContextCompat.checkSelfPermission
|
|
17
|
+
import com.regula.documentreader.api.ble.BLEWrapper
|
|
18
|
+
import com.regula.documentreader.api.ble.BleWrapperCallback
|
|
19
|
+
import com.regula.documentreader.api.ble.RegulaBleService
|
|
20
|
+
import com.regula.documentreader.api.internal.permission.BluetoothPermissionHelper.BLE_ACCESS_PERMISSION
|
|
21
|
+
import com.regula.documentreader.api.internal.permission.BluetoothSettingsHelper.isBluetoothEnabled
|
|
22
|
+
import com.regula.documentreader.api.internal.permission.BluetoothSettingsHelper.isLocationServiceEnabled
|
|
23
|
+
|
|
24
|
+
class BluetoothUtil {
|
|
25
|
+
companion object {
|
|
26
|
+
private const val REQUEST_ENABLE_LOCATION = 196
|
|
27
|
+
private const val REQUEST_ENABLE_BT = 197
|
|
28
|
+
|
|
29
|
+
@SuppressLint("StaticFieldLeak")
|
|
30
|
+
var bleManager: BLEWrapper? = null
|
|
31
|
+
|
|
32
|
+
@RequiresPermission("android.permission.BLUETOOTH_CONNECT")
|
|
33
|
+
private fun requestEnableBle(activity: Activity) {
|
|
34
|
+
val enableIntent = Intent(BluetoothAdapter.ACTION_REQUEST_ENABLE)
|
|
35
|
+
activity.startActivityForResult(enableIntent, REQUEST_ENABLE_BT)
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
private fun requestEnableLocationService(activity: Activity) {
|
|
39
|
+
val myIntent = Intent(Settings.ACTION_LOCATION_SOURCE_SETTINGS)
|
|
40
|
+
activity.startActivityForResult(myIntent, REQUEST_ENABLE_LOCATION)
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
// requestEnableBle() is called after a check for permission
|
|
44
|
+
@SuppressLint("MissingPermission")
|
|
45
|
+
fun isBlePermissionsGranted(activity: Activity): Boolean {
|
|
46
|
+
if (!isLocationServiceEnabled(activity)) {
|
|
47
|
+
requestEnableLocationService(activity)
|
|
48
|
+
return false
|
|
49
|
+
}
|
|
50
|
+
deniedBluetoothPermissions(activity)?.let {
|
|
51
|
+
requestPermissions(activity, it, BLE_ACCESS_PERMISSION)
|
|
52
|
+
return false
|
|
53
|
+
}
|
|
54
|
+
if (!isBluetoothEnabled(activity)) {
|
|
55
|
+
requestEnableBle(activity)
|
|
56
|
+
return false
|
|
57
|
+
}
|
|
58
|
+
return true
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
private fun deniedBluetoothPermissions(activity: Activity): Array<String>? {
|
|
62
|
+
val result = mutableListOf<String>()
|
|
63
|
+
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
|
|
64
|
+
result.addAll(deniedBluetoothPermission(activity, BLUETOOTH_SCAN))
|
|
65
|
+
result.addAll(deniedBluetoothPermission(activity, BLUETOOTH_CONNECT))
|
|
66
|
+
} else
|
|
67
|
+
result.addAll(deniedBluetoothPermission(activity, ACCESS_FINE_LOCATION))
|
|
68
|
+
return result.let { if (it.size > 0) it.toTypedArray() else null }
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
private fun deniedBluetoothPermission(
|
|
72
|
+
activity: Activity,
|
|
73
|
+
permission: String
|
|
74
|
+
): Array<String> {
|
|
75
|
+
if (checkSelfPermission(activity, permission) != PERMISSION_GRANTED)
|
|
76
|
+
return arrayOf(permission)
|
|
77
|
+
return arrayOf()
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
fun startBluetoothService(
|
|
81
|
+
activity: Activity,
|
|
82
|
+
onConnected: (Boolean) -> Unit,
|
|
83
|
+
onDisconnected: () -> Unit,
|
|
84
|
+
onReady: () -> Unit,
|
|
85
|
+
) {
|
|
86
|
+
val bleIntent = Intent(activity, RegulaBleService::class.java)
|
|
87
|
+
activity.startService(bleIntent)
|
|
88
|
+
|
|
89
|
+
activity.bindService(bleIntent, object : ServiceConnection {
|
|
90
|
+
override fun onServiceConnected(name: ComponentName, service: IBinder) {
|
|
91
|
+
bleManager = (service as RegulaBleService.LocalBinder).service.bleManager
|
|
92
|
+
val isBleManagerConnected = bleManager?.isConnected == true
|
|
93
|
+
onConnected(isBleManagerConnected)
|
|
94
|
+
if (!isBleManagerConnected) {
|
|
95
|
+
bleManager?.addCallback(object : BleWrapperCallback() {
|
|
96
|
+
override fun onDeviceReady() {
|
|
97
|
+
bleManager!!.removeCallback(this)
|
|
98
|
+
onReady()
|
|
99
|
+
}
|
|
100
|
+
})
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
override fun onServiceDisconnected(name: ComponentName) = onDisconnected()
|
|
105
|
+
}, 0)
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
}
|