2013-10-05 55 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

三江源,我会坚果试图找出问题 –

相关问题