react-native-nfc-manager 4.0.0-beta.4 → 4.0.0-beta.6
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.
|
@@ -45,7 +45,7 @@ class NfcManager extends NativeNfcManagerSpec implements ActivityEventListener,
|
|
|
45
45
|
private static final String LOG_TAG = "ReactNativeNfcManager";
|
|
46
46
|
private final List<IntentFilter> intentFilters = new ArrayList<>();
|
|
47
47
|
private final ArrayList<String[]> techLists = new ArrayList<>();
|
|
48
|
-
private final
|
|
48
|
+
private final ReactApplicationContext context;
|
|
49
49
|
private Boolean isForegroundEnabled = false;
|
|
50
50
|
private Boolean isResumed = false;
|
|
51
51
|
private WriteNdefRequest writeNdefRequest = null;
|
|
@@ -788,6 +788,59 @@ class NfcManager extends NativeNfcManagerSpec implements ActivityEventListener,
|
|
|
788
788
|
}
|
|
789
789
|
}
|
|
790
790
|
|
|
791
|
+
@ReactMethod
|
|
792
|
+
public void getTimeout(Callback callback) {
|
|
793
|
+
synchronized (this) {
|
|
794
|
+
if (techRequest != null) {
|
|
795
|
+
try {
|
|
796
|
+
String tech = techRequest.getTechType();
|
|
797
|
+
TagTechnology baseTechHandle = techRequest.getTechHandle();
|
|
798
|
+
// TagTechnology is the base class for each tech (ex, NfcA, NfcB, IsoDep ...)
|
|
799
|
+
// but it doesn't provide transceive in its interface, so we need to explicitly cast it
|
|
800
|
+
switch (tech) {
|
|
801
|
+
case "NfcA": {
|
|
802
|
+
NfcA techHandle = (NfcA) baseTechHandle;
|
|
803
|
+
int timeout = techHandle.getTimeout();
|
|
804
|
+
callback.invoke(null, timeout);
|
|
805
|
+
return;
|
|
806
|
+
}
|
|
807
|
+
case "NfcF": {
|
|
808
|
+
NfcF techHandle = (NfcF) baseTechHandle;
|
|
809
|
+
int timeout = techHandle.getTimeout();
|
|
810
|
+
callback.invoke(null, timeout);
|
|
811
|
+
return;
|
|
812
|
+
}
|
|
813
|
+
case "IsoDep": {
|
|
814
|
+
IsoDep techHandle = (IsoDep) baseTechHandle;
|
|
815
|
+
int timeout = techHandle.getTimeout();
|
|
816
|
+
callback.invoke(null, timeout);
|
|
817
|
+
return;
|
|
818
|
+
}
|
|
819
|
+
case "MifareClassic": {
|
|
820
|
+
MifareClassic techHandle = (MifareClassic) baseTechHandle;
|
|
821
|
+
int timeout = techHandle.getTimeout();
|
|
822
|
+
callback.invoke(null, timeout);
|
|
823
|
+
return;
|
|
824
|
+
}
|
|
825
|
+
case "MifareUltralight": {
|
|
826
|
+
MifareUltralight techHandle = (MifareUltralight) baseTechHandle;
|
|
827
|
+
int timeout = techHandle.getTimeout();
|
|
828
|
+
callback.invoke(null, timeout);
|
|
829
|
+
return;
|
|
830
|
+
}
|
|
831
|
+
}
|
|
832
|
+
Log.d(LOG_TAG, "getTimeout not supported");
|
|
833
|
+
callback.invoke(ERR_API_NOT_SUPPORT);
|
|
834
|
+
} catch (Exception ex) {
|
|
835
|
+
Log.d(LOG_TAG, ex.toString());
|
|
836
|
+
callback.invoke(ex.toString());
|
|
837
|
+
}
|
|
838
|
+
} else {
|
|
839
|
+
callback.invoke(ERR_NO_TECH_REQ);
|
|
840
|
+
}
|
|
841
|
+
}
|
|
842
|
+
}
|
|
843
|
+
|
|
791
844
|
@ReactMethod
|
|
792
845
|
public void connect(ReadableArray techs, Callback callback){
|
|
793
846
|
synchronized(this) {
|
|
@@ -1007,7 +1060,7 @@ class NfcManager extends NativeNfcManagerSpec implements ActivityEventListener,
|
|
|
1007
1060
|
Log.d(LOG_TAG, "start");
|
|
1008
1061
|
|
|
1009
1062
|
IntentFilter filter = new IntentFilter(NfcAdapter.ACTION_ADAPTER_STATE_CHANGED);
|
|
1010
|
-
Activity currentActivity = getCurrentActivity();
|
|
1063
|
+
Activity currentActivity = context.getCurrentActivity();
|
|
1011
1064
|
if (currentActivity == null) {
|
|
1012
1065
|
callback.invoke(ERR_GET_ACTIVITY_FAIL);
|
|
1013
1066
|
return;
|
|
@@ -1027,7 +1080,7 @@ class NfcManager extends NativeNfcManagerSpec implements ActivityEventListener,
|
|
|
1027
1080
|
@ReactMethod
|
|
1028
1081
|
public void isSupported(String tech, Callback callback){
|
|
1029
1082
|
Log.d(LOG_TAG, "isSupported");
|
|
1030
|
-
Activity currentActivity = getCurrentActivity();
|
|
1083
|
+
Activity currentActivity = context.getCurrentActivity();
|
|
1031
1084
|
if (currentActivity == null) {
|
|
1032
1085
|
callback.invoke(ERR_GET_ACTIVITY_FAIL);
|
|
1033
1086
|
return;
|
|
@@ -1065,7 +1118,7 @@ class NfcManager extends NativeNfcManagerSpec implements ActivityEventListener,
|
|
|
1065
1118
|
@ReactMethod
|
|
1066
1119
|
public void goToNfcSetting(Callback callback) {
|
|
1067
1120
|
Log.d(LOG_TAG, "goToNfcSetting");
|
|
1068
|
-
Activity currentActivity = getCurrentActivity();
|
|
1121
|
+
Activity currentActivity = context.getCurrentActivity();
|
|
1069
1122
|
if (currentActivity == null) {
|
|
1070
1123
|
callback.invoke(ERR_GET_ACTIVITY_FAIL);
|
|
1071
1124
|
return;
|
|
@@ -1081,7 +1134,7 @@ class NfcManager extends NativeNfcManagerSpec implements ActivityEventListener,
|
|
|
1081
1134
|
|
|
1082
1135
|
@ReactMethod
|
|
1083
1136
|
public void getLaunchTagEvent(Callback callback) {
|
|
1084
|
-
Activity currentActivity = getCurrentActivity();
|
|
1137
|
+
Activity currentActivity = context.getCurrentActivity();
|
|
1085
1138
|
if (currentActivity == null) {
|
|
1086
1139
|
callback.invoke(ERR_GET_ACTIVITY_FAIL);
|
|
1087
1140
|
return;
|
|
@@ -1297,7 +1350,7 @@ class NfcManager extends NativeNfcManagerSpec implements ActivityEventListener,
|
|
|
1297
1350
|
private void enableDisableForegroundDispatch(boolean enable) {
|
|
1298
1351
|
Log.i(LOG_TAG, "enableForegroundDispatch, enable = " + enable);
|
|
1299
1352
|
NfcAdapter nfcAdapter = NfcAdapter.getDefaultAdapter(context);
|
|
1300
|
-
Activity currentActivity = getCurrentActivity();
|
|
1353
|
+
Activity currentActivity = context.getCurrentActivity();
|
|
1301
1354
|
final NfcManager manager = this;
|
|
1302
1355
|
if (nfcAdapter != null && currentActivity != null && !currentActivity.isFinishing()) {
|
|
1303
1356
|
try {
|
|
@@ -1354,7 +1407,7 @@ class NfcManager extends NativeNfcManagerSpec implements ActivityEventListener,
|
|
|
1354
1407
|
}
|
|
1355
1408
|
|
|
1356
1409
|
private PendingIntent getPendingIntent() {
|
|
1357
|
-
Activity activity = getCurrentActivity();
|
|
1410
|
+
Activity activity = context.getCurrentActivity();
|
|
1358
1411
|
assert activity != null;
|
|
1359
1412
|
Intent intent = new Intent(activity, activity.getClass());
|
|
1360
1413
|
intent.addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP | Intent.FLAG_ACTIVITY_CLEAR_TOP);
|
package/index.d.ts
CHANGED
|
@@ -284,6 +284,7 @@ declare module 'react-native-nfc-manager' {
|
|
|
284
284
|
transceive(bytes: number[]): Promise<number[]>;
|
|
285
285
|
getMaxTransceiveLength(): Promise<number>;
|
|
286
286
|
setTimeout(timeout: number): Promise<void>;
|
|
287
|
+
getTimeout(): Promise<number|void>;
|
|
287
288
|
connect: (techs: NfcTech[]) => Promise<void>;
|
|
288
289
|
close: () => Promise<void>;
|
|
289
290
|
mifareClassicHandlerAndroid: MifareClassicHandlerAndroid;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-native-nfc-manager",
|
|
3
|
-
"version": "4.0.0-beta.
|
|
3
|
+
"version": "4.0.0-beta.6",
|
|
4
4
|
"description": "A NFC module for react native.",
|
|
5
5
|
"main": "src/index.js",
|
|
6
6
|
"repository": {
|
|
@@ -64,7 +64,7 @@
|
|
|
64
64
|
"typescript": "^4.1.3"
|
|
65
65
|
},
|
|
66
66
|
"peerDependencies": {
|
|
67
|
-
"@expo/config-plugins": "
|
|
67
|
+
"@expo/config-plugins": "*"
|
|
68
68
|
},
|
|
69
69
|
"peerDependenciesMeta": {
|
|
70
70
|
"@expo/config-plugins": {
|
|
@@ -57,6 +57,7 @@ export interface Spec extends TurboModule {
|
|
|
57
57
|
goToNfcSetting(callback: (err?: string) => void): void;
|
|
58
58
|
getLaunchTagEvent(callback: (err?: string, tag?: Object) => void): void;
|
|
59
59
|
setTimeout(timeout: number, callback: (err?: string, tag?: Object) => void): void;
|
|
60
|
+
getTimeout(callback: (err?: string, timeout?: number) => void): void;
|
|
60
61
|
connect(techs: string[], callback: (err?: string) => void): void;
|
|
61
62
|
close(callback: (err?: string) => void): void;
|
|
62
63
|
transceive(bytes: number[], callback: (err?: string, bytes?: number[]) => void): void;
|
package/src/NfcManager.js
CHANGED
package/src/NfcManagerAndroid.js
CHANGED
|
@@ -84,6 +84,8 @@ class NfcManagerAndroid extends NfcManagerBase {
|
|
|
84
84
|
setTimeout = (timeout) =>
|
|
85
85
|
handleNativeException(callNative('setTimeout', [timeout]));
|
|
86
86
|
|
|
87
|
+
getTimeout = () => handleNativeException(callNative('getTimeout'));
|
|
88
|
+
|
|
87
89
|
connect = (techs) => handleNativeException(callNative('connect', [techs]));
|
|
88
90
|
|
|
89
91
|
close = () => handleNativeException(callNative('close'));
|