Reputation: 6983
I'm trying to learn NFC, using the document at http://www.tappednfc.com/wp-content/uploads/TAPPED-NFCDeveloperGuide-Part1.pdf.
Where my class id defined, i get the following error:
must implement abstract method NfcAdapter.OnNdefPushCompleteCallback.onNdefPushComplete
I have the following method defined
public void OnNdefPushComplete( NfcEvent arg0)
{
mHandler.obtainMessage(1).sendToTarget();
}
Wouldn't this be the callback the error message is saying I need?
The complete code looks as follows
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();
}
}
Upvotes: 0
Views: 678
Reputation: 40831
Remember that Java is case-sensitive. The method OnNdefPushCompleteCallback.onNdefPushComplete(...)
starts with a lower-case "o" (see the interface definition of OnNdefPushCompleteCallback
:
public void onNdefPushComplete(NfcEvent arg0) {
mHandler.obtainMessage(1).sendToTarget();
}
Upvotes: 1