From 9607b509b5f4ef7ad96b6e1bac19bad97e94b609 Mon Sep 17 00:00:00 2001 From: Richie Date: Sat, 25 Jun 2022 18:08:36 +0800 Subject: [PATCH] fix(android): avoid native exception while jumping to system NFC settings --- .../main/java/community/revteltech/nfc/NfcManager.java | 8 ++++++-- index.d.ts | 2 +- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/android/src/main/java/community/revteltech/nfc/NfcManager.java b/android/src/main/java/community/revteltech/nfc/NfcManager.java index c479237..116fc67 100644 --- a/android/src/main/java/community/revteltech/nfc/NfcManager.java +++ b/android/src/main/java/community/revteltech/nfc/NfcManager.java @@ -1034,8 +1034,12 @@ public void goToNfcSetting(Callback callback) { return; } - currentActivity.startActivity(new Intent(Settings.ACTION_NFC_SETTINGS)); - callback.invoke(); + try { + currentActivity.startActivity(new Intent(Settings.ACTION_NFC_SETTINGS)); + callback.invoke(null, true); + } catch (Exception ex) { + callback.invoke(null, false); + } } @ReactMethod diff --git a/index.d.ts b/index.d.ts index 258c67c..54c97ed 100644 --- a/index.d.ts +++ b/index.d.ts @@ -271,7 +271,7 @@ declare module 'react-native-nfc-manager' { /** * Android only */ - goToNfcSetting(): Promise; + goToNfcSetting(): Promise; getLaunchTagEvent(): Promise; transceive(bytes: number[]): Promise; getMaxTransceiveLength(): Promise;