As a workaround for a hardware bug in an Android based POS device, I have to use following Java code to capture the NFC Tag Id. Each and every time the device get a NFC input, this Java code can capture its Tag Id and it will be assigned to nfcTagId
inside the switch statement.
I want to pass this nfcTagId
to my Ionic v1 app as soon as the device got hit with a NFC card, and start a broadcast function to invoke other methods. What is the best way to archive this?
import androidx.appcompat.app.AppCompatActivity;
import android.content.Intent;
import android.os.Bundle;
import android.text.Editable;
import android.text.TextWatcher;
import android.view.KeyEvent;
import android.view.View;
import android.widget.EditText;
import android.widget.Toast;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class MainActivity extends AppCompatActivity {
private static final Pattern KEYCODE_PATTERN = Pattern.compile("KEYCODE_(\\w)");
String id = "";
String nfcTagId = "";
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
}
@Override
public boolean onKeyUp(int keyCode, KeyEvent event) {
switch (keyCode) {
case KeyEvent.KEYCODE_ENTER:
nfcTagId = id;
return true;
default:
String key = KeyEvent.keyCodeToString(keyCode);
Matcher matcher = KEYCODE_PATTERN.matcher(key);
if (matcher.matches()) {
id += matcher.group(1);
}
return super.onKeyUp(keyCode, event);
}
}
}