Forum / MIFARE SDK / NTAGI2C TAG ,Andriod Studio, MIFARE SDK Lite
Tagged: Andriod Studio, MIFARE SDK Lite, NTAGI2C TAG
-
Hi;
I am testing a small app that uses the MIFARE SDK Lite with the NTAG12C tag. The tutorial i am following is
UM10809-Getting Started with MIFARE SDK from the mifare. However i am having problem getting
the application to read my Tag, the Nxpnfcliblitecallback () callback method is the issue i believe.
Thanks
michaeljnr
package calex.nxpntag;
import android.content.Intent;
import android.nfc.TagLostException;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.util.Log;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.TextView;
import android.widget.Toast;
import com.nxp.nfclib.classic.MFClassic;
import com.nxp.nfclib.exceptions.SmartCardException;
import com.nxp.nfclib.icode.ICodeSLI;
import com.nxp.nfclib.icode.ICodeSLIL;
import com.nxp.nfclib.icode.ICodeSLIS;
import com.nxp.nfclib.icode.ICodeSLIX;
import com.nxp.nfclib.icode.ICodeSLIX2;
import com.nxp.nfclib.icode.ICodeSLIXL;
import com.nxp.nfclib.icode.ICodeSLIXS;
import com.nxp.nfclib.ntag.NTag;
import com.nxp.nfclib.ntag.NTag203x;
import com.nxp.nfclib.ntag.NTag210;
import com.nxp.nfclib.ntag.NTag213215216;
import com.nxp.nfclib.ntag.NTag213F216F;
import com.nxp.nfclib.ntag.NTagI2C;
import com.nxp.nfclib.plus.PlusSL1;
import com.nxp.nfclib.ultralight.Ultralight;
import com.nxp.nfclib.ultralight.UltralightC;
import com.nxp.nfclib.ultralight.UltralightEV1;
import com.nxp.nfclib.utils.Utilities;
import com.nxp.nfcliblite.Interface.Inxpnfcliblitecallback;
import com.nxp.nfcliblite.Interface.NxpNfcLibLite;
import com.nxp.nfcliblite.Interface.Nxpnfcliblitecallback;
import com.nxp.nfcliblite.cards.DESFire;
import com.nxp.nfcliblite.cards.Plus;
import java.io.IOException;
import java.util.Arrays;
public class MainActivity extends ActionBarActivity {
// Create an instance of the library object a
private NxpNfcLibLite libInstance = null;
// Tv
private TextView mytext;
private TextView mytext2;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
// Get the instance of the NxpNFcLib
libInstance = NxpNfcLibLite.getInstance();
// Call registerActivity function before using other functions of the library.
// Register the library to the main activity
libInstance.registerActivity(MainActivity.this);
// Initialize the tv view
mytext = (TextView)findViewById(R.id.txt);
mytext2 = (TextView)findViewById(R.id.textView);
}
@Override
protected void onStart() {
// TODO Auto-generated method stub
super.onStart();
}
@Override
protected void onPause() {
super.onPause();
// Stops the fore ground dispatch.
libInstance.stopForeGroundDispatch();
}
@Override
protected void onResume() {
super.onResume();
// Starts Fore ground dispatch on registered activity
// and all the NFC intents is first delivered to the registered activity.
libInstance.startForeGroundDispatch();
}
// Add applicatio logic in this method
protected void onNewIntent(Intent intent) {
// Get the library version once the phone brought close to the tag.
String str = NxpNfcLibLite.getVersion();
// Set tv to display library version
mytext.setText(str);
// Get the support card include in the libray
String[] supportedCard = libInstance.getSupportedCards();
// Display the version in the tv
// String sc = Arrays.toString(supportedCard);
// Set the tv
// mytext2.setText(sc);
// NxpNfcLib abstract class callback to add manually the methods NTagI2c tag
Nxpnfcliblitecallback callback = new Nxpnfcliblitecallback() {
// This function is called when any one of NTagI2C1K NTagI2C2K cards is detected.
private String TAG;
public void onNTagI2CCardDetected(NTagI2C nTagI2C) {
// super.onNTagI2CCardDetected(nTagI2C);
try {
Log.i(TAG, "Ntag Dectected.");
nTagI2C.connect();
Toast.makeText(MainActivity.this, "NTagI2C tag detected",Toast.LENGTH_SHORT).show();
// Application logic
} catch (IOException e) {
e.printStackTrace();
}
}
};
libInstance.filterIntent(intent, callback);
// MifareUltralight.get(tag)
super.onNewIntent(intent);
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_main, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long
// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}
+ 0 | - 0
Hey Michael,
Could you please provide your LOGCAT error / error description from your log ?
This would help me alot by defining the problem and the trying to solve it.
Best,
David
+ 0 | - 0
-
AuthorPosts
Viewing 2 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic.