android nfc设置切换监听器

时间:2013-01-08 18:21:27

标签: android toggle nfc

我想在设置首选项时听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的状态吗?请帮忙.. !!

1 个答案:

答案 0 :(得分:6)

此Intent的名称是“android.nfc.action.ADAPTER_STATE_CHANGED”,而不是“android.nfc.action.ADAPTER_STATE_CHANGE”。请注意已更改上的 D