Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[#170150939] Nfc status should be asked with Context #21

Merged
merged 1 commit into from
Dec 6, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions cieidsdk/src/main/java/it/ipzs/cieidsdk/common/CieIDSdk.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down