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