title: Unable to push NdefMessage with 4.x Android NFC API
body: <p>I am implementing CreateNdefMessageCallback and OnNdefPushCompleteCallback. For some reason the callback methods are NEVER touched, no errors on the log either.</p>
  
  <p>I do hear the sound from the API though, the phone that I am debugging on is a Nexus S running version 4.0.4.</p>
  
  <p>Here is my activity:</p>
  
  <pre><code>public class TestActivity extends Activity implements CreateNdefMessageCallback, OnNdefPushCompleteCallback
  {
    private static SoundHelper soundHelper;
  
    private PowerManager.WakeLock wakeLock;
  
    private NfcAdapter nfcAdapter;
    private PendingIntent pendingIntent = null;
    private IntentFilter[] intentFiltersArray;
    private String[][] techListsArray;
  
    private TextView onScreenLog;
    private List&lt;String&gt; uniqueTagsRead = new ArrayList&lt;String&gt;();
  
    /** handler stuff */
    private static final int MESSAGE_SENT = 1;
    private final Handler handler = new Handler()
    {
      @Override
      public void handleMessage(Message msg)
      {
        switch (msg.what)
        {
          case MESSAGE_SENT:
            if (soundHelper != null)
            {
              soundHelper.playSound(R.raw.smw_coin);
            }
  
            updateTagCount();
            break;
        }
      }
    };
  
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState)
    {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.test);
  
      soundHelper = new SoundHelper(this);
  
      onScreenLog = (TextView) findViewById(R.id.log);
  
      // nfc adapter
      nfcAdapter = NfcAdapter.getDefaultAdapter(this);
      if (nfcAdapter != null)
      {
        // callbacks
        nfcAdapter.setNdefPushMessageCallback(this, this);
        nfcAdapter.setOnNdefPushCompleteCallback(this, this);
  
        // other stuff
        nfcAdapter = NfcAdapter.getDefaultAdapter(this);
        pendingIntent = PendingIntent.getActivity(this, 0, new Intent(this, getClass()).addFlags(Intent.FLAG_ACTIVITY_SINGLE_TOP), 0);
        IntentFilter ndef = new IntentFilter(NfcAdapter.ACTION_NDEF_DISCOVERED);
        try
        {
          ndef.addDataType("*/*");
        }
        catch (MalformedMimeTypeException e)
        {
          throw new RuntimeException("fail", e);
        }
        intentFiltersArray = new IntentFilter[] {ndef, };
        techListsArray = new String[][] {
            new String[] { IsoDep.class.getName() },
            new String[] { NfcA.class.getName() },
            new String[] { NfcB.class.getName() },
            new String[] { NfcF.class.getName() },
            new String[] { NfcV.class.getName() },
            new String[] { Ndef.class.getName() },
            new String[] { NdefFormatable.class.getName() },
            new String[] { MifareClassic.class.getName() },
            new String[] { MifareUltralight.class.getName() },
        };
      }
      else
      {
        onScreenLog.setText("NFC is not available on this device. :(");
      }
    }
  
    public void onPause()
    {
      super.onPause();
  
      // end wake lock
      wakeLock.release();
  
      nfcAdapter.disableForegroundDispatch(this);
    }
  
    public void onResume()
    {
      super.onResume();
  
      // start wake lock
      PowerManager powerManager = (PowerManager) getSystemService(Context.POWER_SERVICE);
      wakeLock = powerManager.newWakeLock(PowerManager.FULL_WAKE_LOCK, "DoNotDimScreen");
      wakeLock.acquire();
  
      nfcAdapter.enableForegroundDispatch(this, pendingIntent, intentFiltersArray, techListsArray);
    }
  
    private void updateTagCount()
    {
      String newCount = String.valueOf(uniqueTagsRead.size());
      String text = getString(R.string.format_count);
      text = getString(R.string.format_count).replace("0", newCount);
  
      onScreenLog.setText(text);
    }
  
    @Override
    public NdefMessage createNdefMessage(NfcEvent event)
    {
      String message = "This is NFC message";
      NdefRecord mimeRecord = createMimeRecord("application/param.android.sample.beam",
      message.getBytes());
      NdefRecord appRecord = NdefRecord.createApplicationRecord("param.android.sample.beam");
      NdefRecord[] ndefRecords = new NdefRecord[] {
      mimeRecord,
      appRecord
      };
      NdefMessage ndefMessage = new NdefMessage(ndefRecords);
      return ndefMessage;
  
      /*
      String mimeType = "text/plain"; // "text/plain";
  
      NdefRecord[] data = {createMimeRecord(mimeType, TEXT_TO_WRITE.getBytes())};
      // data[data.length - 1] = NdefRecord.createApplicationRecord(); // com.test.nfc.application.activities.
  
      return new NdefMessage(data);
      */
    }
  
    /**
     * Creates a custom MIME type encapsulated in an NDEF record
     *
     * @param mimeType
     */
    public NdefRecord createMimeRecord(String mimeType, byte[] payload)
    {
      byte[] mimeBytes = mimeType.getBytes(Charset.forName("US-ASCII"));
      NdefRecord mimeRecord = new NdefRecord(NdefRecord.TNF_MIME_MEDIA, mimeBytes, new byte[0], payload);
  
      return mimeRecord;
    }
  
    @Override
    public void onNdefPushComplete(NfcEvent event)
    {
      handler.obtainMessage(MESSAGE_SENT).sendToTarget();
    }
  }
  </code></pre>
  
  <p>manifest:
      
      </p>
  
  <pre><code>    &lt;uses-sdk android:minSdkVersion="14" /&gt;
  
      &lt;supports-screens android:anyDensity="true" /&gt; 
  
      &lt;uses-permission android:name="android.permission.NFC"/&gt;
      &lt;uses-permission android:name="android.permission.INTERNET"/&gt;
      &lt;uses-permission android:name="android.permission.WAKE_LOCK" /&gt;
  
      &lt;uses-feature android:name="android.hardware.nfc" /&gt;
  
      &lt;application android:name="com.test.nfc.application.Application"
          android:icon="@drawable/icon_launcher_nfc_droid_hdpi"
          android:theme="@android:style/Theme.Light"
          android:label="@string/app_name"&gt;
  
          &lt;activity
              android:label="@string/app_name"
              android:name=".application.activities.MainActivity"
              android:configChanges="orientation|keyboardHidden"&gt;
              &lt;intent-filter &gt;
                  &lt;action android:name="android.intent.action.MAIN" /&gt;
                  &lt;category android:name="android.intent.category.LAUNCHER" /&gt;
              &lt;/intent-filter&gt;
          &lt;/activity&gt;
  
          &lt;activity
              android:label="@string/test"
              android:name=".application.activities.TestActivity"
              android:configChanges="orientation|keyboardHidden"
              android:launchMode="singleTop"&gt;
  
              &lt;intent-filter&gt;
                &lt;action android:name="android.nfc.action.TECH_DISCOVERED"/&gt;
              &lt;/intent-filter&gt;
              &lt;meta-data android:name="android.nfc.action.TECH_DISCOVERED" android:resource="@xml/nfc_tech_list" /&gt;
  
          &lt;/activity&gt;
  
      &lt;/application&gt;
  
  &lt;/manifest&gt;
  </code></pre>
  
  <p>techlist</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;resources xmlns:xliff="urn:oasis:names:tc:xliff:document:1.2"&gt;
      &lt;tech-list&gt;
          &lt;tech&gt;android.nfc.tech.IsoDep&lt;/tech&gt;
          &lt;tech&gt;android.nfc.tech.NfcA&lt;/tech&gt;
          &lt;tech&gt;android.nfc.tech.NfcB&lt;/tech&gt;
          &lt;tech&gt;android.nfc.tech.NfcF&lt;/tech&gt;
          &lt;tech&gt;android.nfc.tech.NfcV&lt;/tech&gt;
          &lt;tech&gt;android.nfc.tech.Ndef&lt;/tech&gt;
          &lt;tech&gt;android.nfc.tech.NdefFormatable&lt;/tech&gt;
          &lt;tech&gt;android.nfc.tech.MifareClassic&lt;/tech&gt;
          &lt;tech&gt;android.nfc.tech.MifareUltralight&lt;/tech&gt;
      &lt;/tech-list&gt;
  &lt;/resources&gt;
  </code></pre>