diff --git a/cieidsdk/src/main/java/it/ipzs/cieidsdk/common/CieIDSdk.kt b/cieidsdk/src/main/java/it/ipzs/cieidsdk/common/CieIDSdk.kt index 3a12c4a..0424067 100644 --- a/cieidsdk/src/main/java/it/ipzs/cieidsdk/common/CieIDSdk.kt +++ b/cieidsdk/src/main/java/it/ipzs/cieidsdk/common/CieIDSdk.kt @@ -205,14 +205,17 @@ object CieIDSdk : NfcAdapter.ReaderCallback { /** * Return true if device has NFC supports */ - fun hasFeatureNFC(context: Activity): Boolean { + fun hasFeatureNFC(context: Context): Boolean { return context.packageManager.hasSystemFeature(PackageManager.FEATURE_NFC) } /** * Return true if NFC is enabled on device */ - fun isNFCEnabled(activity: Activity): Boolean = hasFeatureNFC(activity) && nfcAdapter?.isEnabled ?: false + fun isNFCEnabled(context: Context): Boolean { + val enabled = (context.getSystemService(Context.NFC_SERVICE) as NfcManager).defaultAdapter?.isEnabled ?: false + return hasFeatureNFC(context) && enabled + } /** Open NFC Settings PAge diff --git a/cieidsdk/src/main/java/it/ipzs/cieidsdk/native_bridge/CieModule.kt b/cieidsdk/src/main/java/it/ipzs/cieidsdk/native_bridge/CieModule.kt index dc53a5f..e23aab2 100644 --- a/cieidsdk/src/main/java/it/ipzs/cieidsdk/native_bridge/CieModule.kt +++ b/cieidsdk/src/main/java/it/ipzs/cieidsdk/native_bridge/CieModule.kt @@ -70,12 +70,13 @@ class CieModule(reactContext: ReactApplicationContext) : ReactContextBaseJavaMod @ReactMethod fun isNFCEnabled(callback: com.facebook.react.bridge.Callback) { - callback.invoke(CieIDSdk.isNFCEnabled(getCurrentActivity()!!)) + + callback.invoke(CieIDSdk.isNFCEnabled(reactApplicationContext)) } @ReactMethod fun hasNFCFeature(callback: com.facebook.react.bridge.Callback) { - callback.invoke(CieIDSdk.hasFeatureNFC(getCurrentActivity()!!)) + callback.invoke(CieIDSdk.hasFeatureNFC(reactApplicationContext)) } @ReactMethod