我正在製作一個可讓NFC設置啓動的小部件,現在我只需要知道如何在NFC onReceive中註冊一個意圖,無論是否打開/關閉。因爲我可以註冊一個意圖,當NFC開關打開/關閉時聽?
任何幫助將不勝感激。
@Override
public void onReceive(Context context, Intent intent)
{
manager = (NfcManager) context.getSystemService(Context.NFC_SERVICE);
adapter = manager.getDefaultAdapter();
//OR
if (NfcAdapter.ACTION_NDEF_DISCOVERED.equals(intent.getAction()))
{
actualizar(context);
}
//OR
if (intent.getAction().equals("ADAPTER_STATE_CHANGE"))
{
actualizar(context);
}
}