OpenDigg

android-nfc: An Open-Source NFC Library for Android

android-nfc is a robust open-source NFC library for Android, offering NFC-related features and functionalities, including reading and writing NFC tag information and NFC card emulation, suitable for various NFC application scenarios.

Introduction:
android-nfc is an open-source NFC library based on Java, offering NFC-related functionalities to Android developers. It supports Android 4.4 (KitKat) and above.

Example Code (Java):

import android.nfc.NfcAdapter;
import android.nfc.Tag;

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        // Get the NFC adapter
        NfcAdapter nfcAdapter = NfcAdapter.getDefaultAdapter(this);

        // Register an NFC listener
        nfcAdapter.setOnTagDiscoveredListener(new NfcAdapter.OnTagDiscoveredListener() {
            @Override
            public void onTagDiscovered(Tag tag) {
                // Get NFC tag information
                byte[] tagId = tag.getId();
                String tagType = tag.getTechList()[0].toString();

                // Process NFC tag information
                Log.d("NFC", "tagId: " + Arrays.toString(tagId));
                Log.d("NFC", "tagType: " + tagType);
            }
        });
    }
}

Please use the code with caution. Refer to the documentation for more details.

Key Features:

  1. Read NFC tag information.
  2. Write NFC tag information.
  3. Start NFC card emulation.

Downloading:
android-nfc can be downloaded from GitHub:

git clone https://github.com/android/android-nfc.git

Installation:
android-nfc has the following dependencies:

  • Android SDK

You can install it as follows:

cd android-nfc
./gradlew build

Usage:
For detailed instructions on how to use android-nfc, please refer to the documentation:

https://developer.android.com/reference/android/nfc/package-summary

In conclusion, android-nfc is a powerful NFC library suitable for various NFC application scenarios. It offers the following advantages:

  1. Supports Android 4.4 and above.
  2. Provides rich functionality.
  3. Clear and understandable code.
  4. Comprehensive documentation.

Additional notes:

android-nfc also provides advanced features such as:

  • NFC card emulation.
  • NFC near-field communication.
  • NFC security.

When using android-nfc, please consider the following:

  • Devices with Android 4.4 and below do not support NFC card emulation.
  • Devices with Android 6.0 and above require NFC permissions to be enabled.
About the author
Robert Harris

Robert Harris

I am a zealous AI info-collector and reporter, shining light on the latest AI advancements. Through various channels, I encapsulate and share innovation with a broader audience.

Great! You’ve successfully signed up.

Welcome back! You've successfully signed in.

You've successfully subscribed to OpenDigg.

Success! Check your email for magic link to sign-in.

Success! Your billing info has been updated.

Your billing was not updated.