2013-10-05 85 views
0

我想學習NFC,使用文檔的http://www.tappednfc.com/wp-content/uploads/TAPPED-NFCDeveloperGuide-Part1.pdf獲得了」 ......必須實現抽象方法NfcAdapter.OnNdefPushCompleteCallback錯誤

那裏有我的類ID定義,我得到以下錯誤: 必須實現抽象方法NfcAdapter.OnNdefPushCompleteCallback.onNdefPushComplete

我有以下方法定義

public void OnNdefPushComplete(NfcEvent arg0) 
{ 
    mHandler.obtainMessage(1).sendToTarget(); 
} 

這是不是可以將錯誤信息說我需要什麼?

回調

完整的代碼如下

public class BeamActivity extends Activity 
          implements CreateNdefMessageCallback, 
            OnNdefPushCompleteCallback { 
    NfcAdapter mNfcAdapter; 

    protected void onCreate(Bundle savedInstanceState) { 
     super.onCreate(savedInstanceState); 
     setContentView(R.layout.activity_main); 

     // see if there is a NFC interface 
     mNfcAdapter=NfcAdapter.getDefaultAdapter(this); 
     if (mNfcAdapter==null) Toast.makeText(this,"no adapter", 
               Toast.LENGTH_SHORT).show(); 

     mNfcAdapter.setNdefPushMessageCallback(this,this); 
     mNfcAdapter.setOnNdefPushCompleteCallback(this,this); 
    } 

    public void OnNdefPushComplete(NfcEvent arg0) { 
     mHandler.obtainMessage(1).sendToTarget(); 
    } 

    private final Handler mHandler = new Handler() { 
     @Override 
     public void handleMessage(Message msg) { 
      switch (msg.what) { 
       case 1: 
        Toast.makeText(getApplicationContext(),"Mesg Sent", 
            Toast.LENGTH_SHORT).show(); 
        break; 
      } // end switch 
     } // end handle mesg 
    }; // end new 

    // create call back code 
    public NdefMessage createNdefMessage(NfcEvent event) { 
     String text="hello world"; 
     //NdefMessage msg = new NdefMessage(new NdefRecord[] { 
     //  NfcUtils. 
     // } 
     return msg; 
    } 

    @Override 
    public void onNewIntent(Intent intent) { 
     setIntent(intent); 
    } 

    @Override 
    public void onResume() { 
     super.onRestart(); 

     if (mNfcAdapter.ACTION_NDEF_DISCOVERED.equals(getIntent().getAction())) { 
      processIntent(getIntent()); 
     } 
    } 

    void processIntent(Intent intet) { 
     Parcelable[] rawMsgs= intet.getParcelableArrayExtra(
       mNfcAdapter.EXTRA_NDEF_MESSAGES); 

     NdefMessage msg = ( NdefMessage) rawMsgs[0]; 
     String s= new String( msg.getRecords()[0].getPayload()); 

     Toast.makeText(getApplicationContext(), s, 
         Toast.LENGTH_SHORT).show(); 
    } 
} 

回答

1

記住,Java是區分大小寫的。 OnNdefPushCompleteCallback.onNdefPushComplete(...)用小寫開頭的方法「O」(見OnNdefPushCompleteCallback接口定義:

public void onNdefPushComplete(NfcEvent arg0) { 
    mHandler.obtainMessage(1).sendToTarget(); 
} 
+0

三江源,我會堅果試圖找出問題 –

相關問題