From 82c403028c8ab0406ce9754f36d04b019459ca57 Mon Sep 17 00:00:00 2001 From: Matteo Boschi Date: Fri, 6 Dec 2019 13:14:18 +0100 Subject: [PATCH] [#170150939] now nfc feature/enabled can be asked with context --- cieidsdk/src/main/java/it/ipzs/cieidsdk/common/CieIDSdk.kt | 7 +++++-- .../main/java/it/ipzs/cieidsdk/native_bridge/CieModule.kt | 5 +++-- 2 files changed, 8 insertions(+), 4 deletions(-) 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