Code:
public void targetDetected(TargetProperties[] targetproperties)
{
try
{
TargetProperties tmp = targetproperties[0];
UID = tmp.getUid();
tagRWForm.LBL_UID.setText("UID : " + UID + " ");
tagRWForm.repaint();
// Dialog.show("INFO","UID read", "Ok", null);
conn = getMFStandardConnection(targetproperties);
// Dialog.show("INFO","Got connection"+conn.toString(), "Ok", null);
// if (targetproperties.length == 0)
// {
//// Dialog.show("INFO","targetproperties.length == 0", "Ok", null);
// read_tag_flag=false;
// }
// else
// {
// read_tag_flag=true;
// }
if (conn == null)
{
Dialog.show("INFO","conn=null", "Ok", null);
read_tag_flag=false;
}
else
{
Dialog.show("INFO","conn="+conn.toString(), "Ok", null);
read_tag_flag = true;
}
if (read_tag_flag)
{
byte[] ki0 = {(byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF};
// Dialog.show("INFO","Preparing key", "Ok", null);
MFKey.KeyA key = new MFKey.KeyA(ki0);
MFBlock BLOCK;
byte[] BLKByte = new byte[16];
String strBlock = "";
if (ReadFlag)
{
KeySetMIDlet.raed.dispose();
System.gc();
try
{
BLOCK = conn.getBlock(Integer.parseInt(tagRWForm.TXT_BlockNo.getText()));
// Dialog.show("INFO","Reading block", "Ok", null);
BLOCK.read(key, BLKByte, 0, 0,16);
strBlock = new String(BLKByte);
// String s = byteToHex(BLKByte);
//BLKByte=hexStringToByteArray(s);
tagRWForm.TXT_Data.setText(strBlock);
Dialog.show("INFO", "Data read successfully from block No. " + tagRWForm.TXT_BlockNo.getText() + ".", Dialog.TYPE_INFO, null, "Ok", null, 1000);
tagRWForm.LBL_UID.setText("UID : " + UID + " ");
tagRWForm.repaint();
ReadFlag = false;
}
catch (Exception ex)
{
Dialog.show("INFO",ex.toString(), "Ok", null);
}
}
else
{
if (WriteFlag)
{
KeySetMIDlet.write.dispose();
System.gc();
try
{
String data = "";
// BLOCK = conn.getBlock(Integer.parseInt(tagRWForm.TXT_BlockNo.getText()));
data = tagRWForm.TXT_Data.getText().trim();
data = addSpacesTo16(data);
// BLOCK.write(key, data.getBytes(), 0, 16, 0);
WriteFlag = false;
Dialog.show("INFO", "Data writen successfully on block No. " + tagRWForm.TXT_BlockNo.getText() + ".", Dialog.TYPE_INFO, null, "Ok", null, 1000);
}
catch (Exception ex)
{
ex.printStackTrace();
}
}
}
try
{
if (conn != null)
{
conn.close();
}
}
catch (Exception ex)
{
}
}
else
{
KeySetMIDlet.raed.dispose();
KeySetMIDlet.write.dispose();
System.gc();
}
}
catch (Exception ep)
{
Dialog.show("INFO", ep.toString(), "OK", "Cancel");
}
finally
{
try
{
if(conn != null)
{
conn.close();
}
}
catch (Exception ex)
{
}
}
}
private MFStandardConnection getMFStandardConnection(TargetProperties[] Prop)
{
for (int j = 0; j < Prop.length; j++)
{
Class[] connections = Prop[j].getConnectionNames();
// for(int i=0;i<connections.length;i++)
// {
// Dialog.show("INFO",connections[i].getName(), "Ok", null);
// }
if (connections != null)
{
for (int k = 0; k < connections.length; k++)
{
// Dialog.show("INFO",connections[k].getName(), "Ok", null);
if (connections[k].getName().equals("com.nokia.nfc.nxp.mfstd.MFStandardConnection"))
{
try
{
//Dialog.show("INFO",Prop[j].getUrl(connections[k]), "Ok", null);
return (MFStandardConnection) Connector.open(Prop[j].getUrl(connections[k]));
}
catch (Exception e)
{
e.printStackTrace();
}
}
}
}
}
return null;
}
Please skalogir help me to get solution