Organizational Research By

Surprising Reserch Topic

Question:Android NFC App not pushing Ndef messages

I am working on creating an Android App that uses NFC to register touches from device to device. I am using two Nexus 7s for testing.

Ideal use case is to have the App active on one device, not active on the other. The active device pushes an NdefMessage with a record containing some data for the passive device app to deal with. The passive device passes a recording containing some data back to the active app.

I have the following intent filters set up in my manifest:

   android:name=".MainActivity" android:label="@string/title_activity_main">

In my MainActivity I have the following in onCreate to set up the NFC adapter:

mNfcAdapter = NfcAdapter.getDefaultAdapter(this);
PendingIntent pendingIntent = PendingIntent.getActivity(
            this, 0, new Intent(this,
                getClass()).addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP), 0);
mNfcPendingIntent = pendingIntent;
    // Intent filters for exchanging over p2p.
if(mNfcAdapter != null){
    IntentFilter ndefDetected = new
    IntentFilter ndef = new IntentFilter(NfcAdapter.ACTION_NDEF_DISCOVERED);
    try {
    catch (MalformedMimeTypeException e) {
        throw new RuntimeException("fail", e);
    this.intentFiltersArray = new IntentFilter[] {ndef, };
    Log.d(this.toString(), "mNfcPendingIntent: ");
    mNdefExchangeFilters = new IntentFilter[] { ndefDetected,defendDetected };



asked Sep 13, 2013 in Core java by rajesh
edited Sep 12, 2013
0 votes

Related Hot Questions

1 Answer

0 votes

I have the following for onNewIntent :

protected void onNewIntent(Intent intent) {
    // NDEF exchange mode
    Log.d("onNewIntent", intent.getAction());
    if (NfcAdapter.ACTION_NDEF_DISCOVERED == (intent.getAction())) {
        NdefMessage[] msgs = getNdefMessages(intent);
        for(int i = 0; i < msgs.length; i++){
            Log.d("onNewIntent", "found new NdefMessage");


Right now, I run this call:

public void setIdleMessage(){
    InteractionHistory intHist = InteractionHistory.getInstance();
    NdefMessage attackNdefMessage = null;
    NdefRecord[] ndefRecords = new NdefRecord[10];
    ndefRecords[0] = NdefRecord.createMime("application/com.killerapprejji.NfcHandle", new String("attack,attacker:"
            + intHist.getDisplayName() 
            + ",attackerid:" + "1").getBytes());
    attackNdefMessage = new NdefMessage(ndefRecords[0]);
    // need to come up with a way to end if the above try/catch fails
    mNfcAdapter.setNdefPushMessage(attackNdefMessage, this);

Expecting it to set the NdefPushMessage. Whenever I touch put the two devices in range of NFC, I still only get the optional "Touch to beam" interface.

Any ideas as to how I can pick up these intents, or if my NdefMessage is even getting sent as I expect?


answered Sep 13, 2013 by rajesh
edited Sep 12, 2013