3

我想在设置首选项中收听 nfc 启用/禁用,所以我在我的活动中添加以下代码

    IntentFilter filter = new IntentFilter("android.nfc.action.ADAPTER_STATE_CHANGE");
    BroadcastReceiver receiver = new BroadcastReceiver() {

        @Override
        public void onReceive(Context context, Intent intent) {
            tv.setText("broadcast received :" + NfcAdapter.getDefaultAdapter(MainActivity.this).isEnabled());
            Toast.makeText(MainActivity.this, "broadcast received", Toast.LENGTH_LONG).show();
        }
    };
    registerReceiver(receiver, filter);

但看起来 ADAPTER_STATE_CHANGE 不起作用。

任何人都可以有一个想法来听 nfc 的状态吗?请帮忙..!!

4

1 回答 1

6

这个 Intent 的名称是“android.nfc.action.ADAPTER_STATE_CHANGED”,而不是“android.nfc.action.ADAPTER_STATE_CHANGE”。请注意CHANGED上的D

于 2013-09-12T11:08:27.897 回答