Skip to content

Commit 115bbbd

Browse files
authored
Merge pull request #792 from tastydev/main
feat(Android): add getTimeout
2 parents 33a35d9 + bdda505 commit 115bbbd

File tree

4 files changed

+58
-0
lines changed

4 files changed

+58
-0
lines changed

android/src/main/java/community/revteltech/nfc/NfcManager.java

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -743,6 +743,59 @@ public void setTimeout(int timeout, Callback callback) {
743743
}
744744
}
745745

746+
@ReactMethod
747+
public void getTimeout(Callback callback) {
748+
synchronized (this) {
749+
if (techRequest != null) {
750+
try {
751+
String tech = techRequest.getTechType();
752+
TagTechnology baseTechHandle = techRequest.getTechHandle();
753+
// TagTechnology is the base class for each tech (ex, NfcA, NfcB, IsoDep ...)
754+
// but it doesn't provide transceive in its interface, so we need to explicitly cast it
755+
switch (tech) {
756+
case "NfcA": {
757+
NfcA techHandle = (NfcA) baseTechHandle;
758+
int timeout = techHandle.getTimeout();
759+
callback.invoke(null, timeout);
760+
return;
761+
}
762+
case "NfcF": {
763+
NfcF techHandle = (NfcF) baseTechHandle;
764+
int timeout = techHandle.getTimeout();
765+
callback.invoke(null, timeout);
766+
return;
767+
}
768+
case "IsoDep": {
769+
IsoDep techHandle = (IsoDep) baseTechHandle;
770+
int timeout = techHandle.getTimeout();
771+
callback.invoke(null, timeout);
772+
return;
773+
}
774+
case "MifareClassic": {
775+
MifareClassic techHandle = (MifareClassic) baseTechHandle;
776+
int timeout = techHandle.getTimeout();
777+
callback.invoke(null, timeout);
778+
return;
779+
}
780+
case "MifareUltralight": {
781+
MifareUltralight techHandle = (MifareUltralight) baseTechHandle;
782+
int timeout = techHandle.getTimeout();
783+
callback.invoke(null, timeout);
784+
return;
785+
}
786+
}
787+
Log.d(LOG_TAG, "getTimeout not supported");
788+
callback.invoke(ERR_API_NOT_SUPPORT);
789+
} catch (Exception ex) {
790+
Log.d(LOG_TAG, ex.toString());
791+
callback.invoke(ex.toString());
792+
}
793+
} else {
794+
callback.invoke(ERR_NO_TECH_REQ);
795+
}
796+
}
797+
}
798+
746799
@ReactMethod
747800
public void connect(ReadableArray techs, Callback callback){
748801
synchronized(this) {

index.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,7 @@ declare module 'react-native-nfc-manager' {
284284
transceive(bytes: number[]): Promise<number[]>;
285285
getMaxTransceiveLength(): Promise<number>;
286286
setTimeout(timeout: number): Promise<void>;
287+
getTimeout(): Promise<number|void>;
287288
connect: (techs: NfcTech[]) => Promise<void>;
288289
close: () => Promise<void>;
289290
mifareClassicHandlerAndroid: MifareClassicHandlerAndroid;

src/NfcManager.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,8 @@ class NfcManagerBase {
106106

107107
setAlertMessage = DoNothing;
108108

109+
getTimeout = DoNothing;
110+
109111
async writeNdefMessage(bytes, options = {}) {
110112
return handleNativeException(callNative('writeNdefMessage', [bytes, options]));
111113
}

src/NfcManagerAndroid.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,8 @@ class NfcManagerAndroid extends NfcManagerBase {
8484
setTimeout = (timeout) =>
8585
handleNativeException(callNative('setTimeout', [timeout]));
8686

87+
getTimeout = () => handleNativeException(callNative('getTimeout'));
88+
8789
connect = (techs) => handleNativeException(callNative('connect', [techs]));
8890

8991
close = () => handleNativeException(callNative('close'));

0 commit comments

Comments
 (0)