利用Java反射机制控制Nfc开关
Nfc状态广播说明
/**
* Used as an int extra field in {@link #ACTION_ADAPTER_STATE_CHANGED}
* intents to request the current power state. Possible values are:
* {@link #STATE_OFF},
* {@link #STATE_TURNING_ON},
* {@link #STATE_ON},
* {@link #STATE_TURNING_OFF},
*/
public static final String EXTRA_ADAPTER_STATE = "android.nfc.extra.ADAPTER_STATE";
public static final int STATE_OFF = 1;
public static final int STATE_TURNING_ON = 2;
public static final int STATE_ON = 3;
public static final int STATE_TURNING_OFF = 4;
/**
* Flag for use with {@link #enableReaderMode(Activity, ReaderCallback, int, Bundle)}.
* <p>
* Setting this flag enables polling for Nfc-A technology.
*/
Nfc状态广播action为“android.nfc.action.ADAPTER_STATE_CHANGED”,在这里他会传递四种int类型的状态值,其中STATE_OFF为关闭完成状态,STATE_ON为准备就绪状态,STATE_TURNING_ON为启动Nfc,STATE_TURNING_OFF为准备关闭状态。
编写BroadcastReceiver来接收Nfc状态
mReceiver = new BroadcastReceiver() {