first of all you should to check if the tag is protected by reading auth0, I would recommand this snip of code:
boolean isTagProtected() {
MifareUltralight mu = MifareUltralight.get(tag);
boolean passExist;
try {
mu.connect();
byte[] answer = mu.readPages(227);
byte auth0 = answer[3];
String text = String.format("%02x", auth0);
Toast.makeText(context, text, Toast.LENGTH_LONG).show();
passExist = auth0 < (byte) 0xEB;
mu.close();
} catch (IOException e) {
e.printStackTrace();
Toast.makeText(context, "cannot make authentication", Toast.LENGTH_SHORT).show();
passExist = true;
}
return passExist;
}
if the tag is not protected you could set new password by this code:
private static final byte[] SET_PACK_VALUE = {(byte) 0xA2, (byte) 0xE6, (byte) 0x11, (byte) 0x11, (byte) 0x00, (byte) 0x00};
private static final byte[] SET_PASSWORD = {(byte) 0xA2, (byte) 0xE5, (byte) 0x75, (byte) 0x6C, (byte) 0x66, (byte) 0x30};
private static final byte[] SET_AUTH0_VALUE = {(byte) 0xA2, (byte) 0xE3, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0xA1};
if (isTagProtected()) {
Toast.makeText(context, "The tag is already Locked", Toast.LENGTH_LONG).show();
} else {
NfcA nfcaTag = NfcA.get(maintag);
try {
nfcaTag.connect();
nfcaTag.transceive(SET_PACK_VALUE);
nfcaTag.transceive(SET_PASSWORD);
nfcaTag.transceive(SET_AUTH0_VALUE);
nfcaTag.close();
Toast.makeText(context, "The tag is locked", Toast.LENGTH_LONG).show();
} catch (IOException e) {
Toast.makeText(context, "Error happend", Toast.LENGTH_LONG).show();
e.printStackTrace();
}
}
it the tag is protected you could auth it to be able to read and write on tag for just one session.
Here how to clear the password :
private final byte[] pwd_auth = new byte[]{(byte) 0x1b,
//here write your pass (4 bytes)
};
public static final byte[] RESET_PACK_VALUE = {(byte) 0xA2, (byte) 0xE6, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00};
public static final byte[] RESET_AUTH0_VALUE = {(byte) 0xA2, (byte) 0xE3, (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0xFF};
MifareUltralight mfu = MifareUltralight.get(maintag);
try {
byte[] answer;
mfu.connect();
answer = mfu.transceive(pwd_auth);
mfu.transceive(MainActivity.RESET_AUTH0_VALUE);
mfu.transceive(MainActivity.RESET_PACK_VALUE);
mfu.close();
Toast.makeText(context, "The Password is deleted", Toast.LENGTH_LONG).show();
} catch (IOException e) {
Toast.makeText(context, "Error happend , wrong pass", Toast.LENGTH_LONG).show();
e.printStackTrace();
}
in other words, you are trying to authenticate a tag wich dosen't have any password.
you should to set a password and then authenicate it.
more general details:

here are more details about tag tech:
the four parameters you need to edit some of them when you are dealing with password are :
PWD 32-bit password used for memory access protection.
Reading PWD always returns 00000000h .
PACK 16-bit password acknowledge used during the password
authentication process.
Reading PACK always returns 0000h
AUTH0 Page address of Sector 0 from which onwards the password
authentication is required to access the user memory from NFC
perspective, dependent on NFC_PROT bit.
If AUTH0 is set to a page address greater than EBh, the
password protection is effectively disabled. Password protected
area starts from page AUTH0 and ends at page EBh.
AUTHLIM no need to explain here.
P.S: I am using NT3H2111_2211 u should to read the link from Andrew in comments to know exactly where should you write PACK, PWD,and AUTH0.