Security News
38% of CISOs Fear They’re Not Moving Fast Enough on AI
CISOs are racing to adopt AI for cybersecurity, but hurdles in budgets and governance may leave some falling behind in the fight against cyber threats.
com.github.skjolber.android.nfc-lifecycle-wrapper:utility
Advanced tools
Library for NFC on Android using androidx lifecycle extensions and functional interfaces.
Features:
Bugs, feature suggestions and help requests can be filed with the issue-tracker.
The project is built with Gradle and is available on the central Maven repository. For
ext {
nfcLifecycleWrapperVersion = '1.0.0'
}
add
api("com.github.skjolber.android-nfc-lifecycle-wrapper:android:${nfcLifecycleWrapper}@aar")
If you prefer a working appliction, see the example.
The library relies on registering an Application.ActivityLifecycleCallbacks
instance in the main Application
(see further down).
Activities wanting to interact with NFC must add the interface NfcActivity
or NfcCompatActivity
and use the NfcFactory
passed in theonPreCreated
or onPostCreated
methods to configure the desired NFC nature:
public void onPreCreated(NfcFactory nfcFactory) {
nfcFactory.newForegroundDispatchBuilder()
.withTagDiscovered( (tag, intent) -> {
// your code here
})
.build();
}
Builders are available for foreground dispatch, reader callback and settings (NFC on/off on the device). Keep a reference to the resulting instance to programmatically enable/disable or ignore the resulting events.
Create a NfcForegroundDispatchBuilder
and pass in the desired (lambda) functions:
nfcFactory.newForegroundDispatchBuilder()
.withTagDiscovered( (tag, intent) -> {
Log.d(TAG, "Tag scanned");
// your code here
})
.withTagRemoved( () -> {
Log.d(TAG, "Tag removed");
// your code here
})
.build();
and keep the resulting built NfcForegroundDispatch
instance if you want to enable/disable or ignore NFC events.
Create a ReaderCallbackBuilder
and pass in the desired (lambda) functions:
nfcFactory.newReaderCallbackBuilder()
.withTagDiscovered( tag -> {
Log.d(TAG, "Tag discovered ");
// your code here
})
.withTagRemoved( () -> {
Log.d(TAG, "Tag removed");
// your code here
})
.withMainThread()
.withAllTagTechnologies()
.build();
and keep the resulting built NfcReaderCallback
instance if you want to enable/disable or ignore NFC events.
The current NFC settings is detected via NfcAdapter
as the Activity
's onResume(..)
is called.
Create a SettingsBuilder
and pass in the desired (lambda) functions:
factory.newSettingsBuilder()
.withEnabled( (transition) -> {
if (transition) {
Log.d(TAG, "NFC setting transitioned to enabled.");
} else {
Log.d(TAG, "NFC setting is still enabled.");
}
})
.withDisabled((transition, available) -> {
if(available) {
if (transition) {
Log.d(TAG, "NFC setting transitioned to disabled.");
} else {
Log.d(TAG, "NFC setting is still disabled.");
}
} else {
if (transition) {
Log.d(TAG, "NFC is not available on this device.");
} else {
Log.d(TAG, "NFC is still not available on this device.");
}
}
})
.build();
and keep the resulting built NfcSettings
instance if you want to enable/disable or ignore NFC Adapter events.
The transition
passed to the lambda functions is true only on the inital call and when NFC is turned on or off on the device. This simplifies user notification if NFC functionality is optional.
Wire up NfcActivityLifecycleCallbacks
or (preferably) NfcCompatActivityLifecycleCallbacks
with registerActivityLifecycleCallbacks
and unregisterActivityLifecycleCallbacks
:
public class NfcApplication extends Application {
protected NfcCompatActivityLifecycleCallbacks callbacks;
public void onCreate() {
super.onCreate();
callbacks = NfcCompatActivityLifecycleCallbacks.newBuilder().withApplication(this).build();
registerActivityLifecycleCallbacks(callbacks);
}
@Override
public void onTerminate() {
super.onTerminate();
unregisterActivityLifecycleCallbacks(callbacks);
}
}
If using AppCompatActivity
, prefer NfcCompatActivityLifecycleCallbacks
, as it is better than NfcActivityLifecycleCallbacks
because it can hook the NFC onPause(..)
and onResume(..)
wireing directly into the Activity
's lifecycle
instance, which removes 'manual' lookup of activity behaviour as the activity stack push / pop.
FAQs
NFC lifecycle wrapper
We found that com.github.skjolber.android.nfc-lifecycle-wrapper:utility demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 0 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
CISOs are racing to adopt AI for cybersecurity, but hurdles in budgets and governance may leave some falling behind in the fight against cyber threats.
Research
Security News
Socket researchers uncovered a backdoored typosquat of BoltDB in the Go ecosystem, exploiting Go Module Proxy caching to persist undetected for years.
Security News
Company News
Socket is joining TC54 to help develop standards for software supply chain security, contributing to the evolution of SBOMs, CycloneDX, and Package URL specifications.