2013-04-16 30 views
0

我正在製作一個可讓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); 
     } 
} 

回答

0

沒有這樣的廣播事件。嘗試閱讀日誌,這將工作,但是非常不可靠和支離破碎。或者,您可以使用NfcAdapter.isEnabled()在您的應用程序中的特定點撥打電話來檢查事情的狀態。

1

一旦您的應用程序被創建並恢復,您可以檢測NFC設置的更改。請參閱this示例。