Mevcut Android uygulamasında herhangi bir NFC etiketi var ve gerekli işlevi yerine getiriyor. Ancak, yalnızca belirli bir UID ile belirli bir etiketle çalışmasını istiyorum. Bunu başarmanın en iyi yolu nedir? Söz konusu etiket içinYalnızca belirli bir NFC etiketi için geçerli olan uygulama
UID geçerli: 046a0b42402b84
NFC fonksiyonu için My kod aşağıda:
public class NFC extends AppCompatActivity {
NfcAdapter nfcAdapter;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_nfc);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
String username = getIntent().getStringExtra("Username");
TextView tv = (TextView) findViewById(R.id.TVusername);
tv.setText(username);
FloatingActionButton fab = (FloatingActionButton) findViewById(R.id.fab);
fab.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Snackbar.make(view, "Replace with your own action", Snackbar.LENGTH_LONG)
.setAction("Action", null).show();
}
});
nfcAdapter = NfcAdapter.getDefaultAdapter(this);
if(nfcAdapter!=null && nfcAdapter.isEnabled()) {
}else{
finish();
}
}
@Override
protected void onNewIntent(Intent intent) {
Toast.makeText(this, "NFC intent received!", Toast.LENGTH_LONG).show();
super.onNewIntent(intent);
}
@Override
protected void onResume() {
Intent intent = new Intent(this, AttendanceRegistration.class);
intent.addFlags(Intent.FLAG_RECEIVER_REPLACE_PENDING);
PendingIntent pendingIntent = PendingIntent.getActivity(this, 0, intent, 0);
IntentFilter[] intentFilter = new IntentFilter[]{};
nfcAdapter.enableForegroundDispatch(this, pendingIntent, intentFilter, null);
super.onResume();
}
@Override
protected void onPause() {
nfcAdapter.disableForegroundDispatch(this);
super.onPause();
}
@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);
}
}
, sorun çözüldü. Teşekkürler –
Özür dilerim, hala bunun için yeni. –
@Micheal Roland Bunu 2 alıcı için nasıl yeniden oluşturabilirim, denemeye ve yakalamaya çalıştım; –