我目前正在创建一个应用程序,它将读取 NFC 标签并根据字符串数组查找标签的文本以查看它是否存在。如果标签区分大小写正确,例如“测试”而不是“测试”,它就可以工作。我尝试了各种方法都没有奏效。有人可以看看我的代码,看看哪个对我来说是最好的解决方案。
以下是相关代码:
String[] dd;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
dd = getResources().getStringArray(R.array.device_description);
}
@Override
protected void onPostExecute(String result) {
if (result != null) {
if(Arrays.asList(dd).contains(result)) {
Vibrator v = (Vibrator)getSystemService(Context.VIBRATOR_SERVICE);
v.vibrate(800);
//mText.setText("Read content: " + result);
Intent newIntent = new Intent(getApplicationContext(), TabsTest.class);
Bundle bundle1 = new Bundle();
bundle1.putString("key", result);
newIntent.putExtras(bundle1);
startActivity(newIntent);
Toast.makeText(getApplicationContext(), "NFC tag written successfully!", Toast.LENGTH_SHORT).show();
}
else{
Toast.makeText(getApplicationContext(), result + " is not in the device description!", Toast.LENGTH_SHORT).show();
}
}
}