Fudi NFC

Platform API License Bintray Jitpack Android Arsenal

by Romell Domínguez

latestVersion is

Add the following in your app’s build.gradle file:

repositories {
    jcenter()
}
dependencies {
    implementation 'com.romellfudi.fudinfc:fudi-nfc:${latestVersion}'
}

Add the following to your AndroidManifest.xml file :

<uses-permission android:name="android.permission.NFC" />

Now go to the created activity, and either

// write email
OpCallback { it.writeEmailToTagFromIntent(text, null, null, intent) }

// write sms
OpCallback { it.writeSmsToTagFromIntent(text, null, intent) }

// write geolocation - latitude & longitude
OpCallback { it.writeGeolocationToTagFromIntent(latitude, longitude, intent) } 

// write uri
OpCallback { it.writeUriToTagFromIntent(text, intent) }

// write phone contact
OpCallback { it.writeTelToTagFromIntent(text, intent) }

// write rolling-on bluetooth device
OpCallback { it.writeBluetoothAddressToTagFromIntent(text, intent) }

Reading

Paste this in the activity if you’re extending our class :

override fun onNewIntent(Intent intent) {
    super.onNewIntent(intent) 
    for (String message in getNfcMessages()) { 
        // message 
    }
}
override fun onNewIntent(intent: Intent?) {
    super.onNewIntent(intent)
    val items: SparseArray<String> = NfcReadUtilityImpl().readFromTagWithSparseArray(intent)
    for (i in 0 until items.size()) {
        // items.valueAt(i) 
    }
}
override fun onNewIntent(intent: Intent?) {
    super.onNewIntent(intent)
    for (message in NfcReadUtilityImpl().readFromTagWithMap(intent).values()) {
        // message
    }
}

Write to a tag

fun onReturn(result: Boolean) {
    val message = if (result) "Success" else "Failed!"
    Toast.makeText(this, message, Toast.LENGTH_SHORT).show()
}

fun onProgressUpdate(vararg booleans: Boolean) {
    Toast.makeText(this, if (booleans[0]) "We started writing" else "We could not write!", Toast.LENGTH_SHORT).show()
}

fun onError(e: Exception) {
    Toast.makeText(this, e.message, Toast.LENGTH_SHORT).show()
}

License

Copyright 2020 Romell D.Z.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.