Giter VIP home page Giter VIP logo

ndef-tools-for-android's Introduction

Build Status Maven Central

Overview

This site hosts a library for Near Field Communication on Android using the NDEF format.

The current (version <= 14.0) Android SDK only comes with a low-level NDEF API which does not expose developers to the full potential of the NDEF format. Rather than sweating over byte arrays, developers should have access to high-level representations.

Features:

  • NDEF object representation library (no more byte arrays!)
    • Simple conversion to and from Android SDK low-level equivalent
  • JSE module with the corresponding Android classes for use in regular Java

In short, this projects helps you to handle dynamic NDEF content at runtime.

License

Apache 2.0

Obtain

The project is built with Gradle and is available on the central Maven repository. For Gradle, configure the property

ext {
  ndefToolsForAndroidVersion = '2.0.1'
}

and add the dependency

api("com.github.skjolber.ndef-tools-for-android:ndeftools:${ndefToolsForAndroidVersion}")

Usage

So a Message consists of a list of Records in the NDEF standard. Browse the source for an overview of supported record types.

Creating new NDEF records

Compose an Android Application Record:

AndroidApplicationRecord aar = new AndroidApplicationRecord();
aar.setPackageName("org.ndeftools.boilerplate");

Compose a Mime Record

MimeRecord mimeRecord = new MimeRecord();
mimeRecord.setMimeType("text/plain");
mimeRecord.setData("This is my data".getBytes("UTF-8"));

Create new NDEF message

From above, simply

Message message = new Message(); //  com.github.skjolber.ndef.Message
message.add(androidApplicationRecord);
message.add(mimeRecord);

or from bytes

byte[] messageBytes = ...; // get your bytes
Message message = Message.parseNdefMessage(messageBytes);

Converting to and from native Android NdefMessage

Use

NdefMessage lowLevel = ...; // get from existing code
Message highLevel = new Message(lowLevel);
// read from high-level records

or

Message highLevel = ...// compose high-level records
NdefMessage lowLevel = highLevel.getNdefMessage();
// .. pass low-level NdefMessage to existing code

JSE module

A few NFC classes copied from the Android open source project, so that the NDEF library can be used on regular Java (i.e. Java 8 or 11).

Example

For a working example see android-nfc-lifecycle-wrapper.

See also

For a graphical NDEF editor, try NFC Eclipse plugin. It creates static NDEF content, and so is good for getting to know the NDEF format. Recommended for developers new to NFC.

Acknowledgements

This project springs out the NFC Tools for Java and NFC Eclipse plugin projects.

History

April 2024: Version 2.0.1 maintenance release.

August 2020: Version 2.0.0 maintenance release:

  • Maven coordinates updated; group is now com.github.skjolber.ndef-tools-for-android
  • Packages renamed to com.github.skjolber.ndef
  • Added Gradle build (now dual builds with Maven)
  • Moved utilities and examples to seperate project
  • Minor improvements

March 28th 2013: Version 1.2.3 released.
February 5th 2013: Version 1.2.2 released.
January 1st 2013: Version 1.2.1 released.
October 18th 2012: Version 1.2 released.
September 15th 2012: Initial release.

ndef-tools-for-android's People

Contributors

dependabot[bot] avatar michal-klimek avatar skjolber avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

ndef-tools-for-android's Issues

Garbage chars displayed for (Abosulte) URI Record

Hello!

After installing nfc-eclipse-plugin I am trying to create Test.ndef file and add a record there: "Absolute URI Record" or "URI Record":

eclipse

Then I try to scan the resulting QR image by using the popular ZXing Barcode Scanner app.

Unfortunately the resulting QR image seems to contain 2 garbage chars:

qr1

qr2

Why does it happen please?

Mavenize

This is a very useful library! Makes reading/writing NFC tags so much easier.

But it would be even better and greatly improves integrating this library into 
Android projects if you make this a Maven project and push the artifacts to 
Maven central repository.

Thank you!

Original issue reported on code.google.com by [email protected] on 23 Feb 2013 at 8:21

  • Blocked on: #2

Refresh project

  • Add more NDEF records, if they exist
  • Update or retire examples.
  • Update documentation
  • Make wrappers for utilities (so that extending activities is not required)
  • Move to gradle

NfcDetectorActivity should use onSaveInstanceState

I run into a problem with NfcDetectorActivity. I completely understand tag dispatch system, and know that each onNewIntent call sets the new Intent as current activity intent. There is a field named "intentProcessed" which ensures no double detections of the same intent when activity is paused and resumed. A problem arises when you just change activity's orientation which in turn triggers (default) activity recreation, and when activity is resumed - tag detection callback is performed again. This leads to write failure callbacks in NfcTagWritterActivity as it thinks that a new tag is in range. I suggest to override onSaveInstanceState in NfcDetectorActivity and store intentProcessed value. This should be read in onCreate callback too. BTW. This project is awesome!

Question: Writing vCard etc

Hi,

first of all lovely lib. I was able to read&write tags in almost no time. I am now interested in writing vCards (phone numbers and contact name), website url, etc on tags.

Can this awesome lib do this aswell? Tried finding some sample code for this purpose, but no luck.

Add http://ndef.codeplex.com/ compatibility

Add automated tests for verifying compatibility to http://ndef.codeplex.com/ 
code NDEF output.


Original issue reported on code.google.com by thomas.skjolberg on 6 May 2013 at 9:33

  • Blocking: #1

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.