小编Vur*_*tne的帖子

Ndef.get(tag) 返回 null

我有这个代码,我总是得到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)

tags android nfc android-intent ndef

2
推荐指数
1
解决办法
3030
查看次数

标签 统计

android ×1

android-intent ×1

ndef ×1

nfc ×1

tags ×1