我有这个代码,我总是得到Ndef ndef = Ndef.get(tag)== null。我试图以不同的方式获得它,但我总是null在同一个地方到达那里。有人知道我做错了什么吗?
private ImageView imgSearch;
private NfcAdapter mAdapter;
private PendingIntent mPendingIntent;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_nfc);
}
@Override
protected void onResume() {
super.onResume();
mAdapter = NfcAdapter.getDefaultAdapter(this);
if (mAdapter == null) {
//nfc not support your device.
Toast.makeText(this, R.string.no_nfc_supported, Toast.LENGTH_SHORT).show();
} else {
mPendingIntent = PendingIntent.getActivity(this, 0, new Intent(this,
getClass()).addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP), 0);
}
mAdapter.enableForegroundDispatch(this, mPendingIntent, null, null);
}
@Override
protected void onPause() {
super.onPause();
if (mAdapter != null) {
mAdapter.disableForegroundDispatch(this);
} …Run Code Online (Sandbox Code Playgroud)