Why isn't Android Beam/NFC receiving the records that I send?
<p>I've read the documentation a few times now and looked at the example code but I can't seem to figure out what I'm doing wrong.</p>

<p>Whenever I put my two devices together I see the Beam screen and tap it, but nothing seems to be sent and none of my breakpoints get hit.
Here's my code, please help me figure out why nothing is sent to the other device. In the editor I can see that everything in <code>BeamFileActivity</code>is run, I just never see any of the break points in <code>MainActivity</code> get accessed on the receiving device. What am I doing wrong?</p>

<p>AndroidManifest.xml:</p>

<pre><code>&lt;manifest xmlns:android="http://schemas.android.com/apk/res/android"
package="com.myapp"&gt;
    &lt;uses-permission android:name="android.permission.NFC" /&gt;
    &lt;uses-feature android:name="android.hardware.nfc" android:required="true" /&gt;
    &lt;application
    android:name=".MainActivity"
    android:allowBackup="true"
    android:icon="@drawable/ic_launcher"
    android:label="@string/app_name"
    android:theme="@style/AppTheme"&gt;
        &lt;meta-data
            android:name="QUERY_LOG"
            android:value="false" /&gt;
        &lt;meta-data
            android:name="DOMAIN_PACKAGE_NAME"
            android:value="com.myapp.domain" /&gt;

        &lt;activity
            android:name=".MainActivity"
            android:exported="true"
            android:label="@string/app_name"
            android:windowSoftInputMode="adjustResize"&gt;

            &lt;intent-filter&gt;
                &lt;action android:name="com.google.android.apps.drive.DRIVE_OPEN" /&gt;
                &lt;action android:name="com.google.android.apps.drive.DRIVE_SAVE" /&gt;
                &lt;data android:mimeType="application/vnd.google-apps.drive-sdk.111111111" /&gt;
                &lt;data android:mimeType="application/vnd.google-apps.spreadsheet" /&gt;
                &lt;action android:name="android.intent.action.MAIN" /&gt;
                &lt;category android:name="android.intent.category.LAUNCHER" /&gt;
            &lt;/intent-filter&gt;
            &lt;intent-filter&gt;
                &lt;action android:name="android.nfc.action.NDEF_DISCOVERED"/&gt;
                &lt;category android:name="android.intent.category.DEFAULT"/&gt;
                &lt;data android:scheme="vnd.android.nfc"
                    android:host="ext"
                    android:pathPrefix="/com.myapp:SpreadsheetDom"/&gt;
            &lt;/intent-filter&gt;
        &lt;/activity&gt;
        &lt;activity
            android:name=".dialog.BeamFileActivity"
            android:label="@string/title_activity_beam_file"
            android:parentActivityName=".MainActivity"
            android:theme="@style/AppTheme.NoActionBar"&gt;
            &lt;meta-data
                android:name="android.support.PARENT_ACTIVITY"
                android:value="com.myapp.MainActivity" /&gt;
        &lt;/activity&gt;
    &lt;/application&gt;
</code></pre>

<p>MainActivity: This is what will receive the Beam intent, I'm only including the methods I think are relevant.</p>

<pre><code>@Override
protected void onResume() {

    super.onResume();

    //I removed some code that reloads my application, didn't seem relevant

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

/**
 * Parses the NDEF Message from the intent and stores the collection
 */
void processIntent(Intent intent) {

    Parcelable[] rawMsgs = intent.getParcelableArrayExtra(NfcAdapter.EXTRA_NDEF_MESSAGES);
    // only one message expected during the beam
    NdefMessage msg = (NdefMessage) rawMsgs[0];

    //This is the data I'm beaming, It has a method that converts its data to a byte array, and a method, fromBytes() that converts bytes into the object
    SpreadsheetDom dom = new SpreadsheetDom();
    try {

        for(int i = 0; i &lt; msg.getRecords().length; i++) {

            if(SpreadsheetDom.class.getName().equalsIgnoreCase(new String(msg.getRecords()[i].getType()))) {

                dom.fromBytes(msg.getRecords()[i].getPayload());
                //removed some code that saves and displays changes
            }
        }
    } catch(IOException | ClassNotFoundException e) {

    }
}

@Override
public void onNewIntent(Intent intent) {

    setIntent(intent);
}
</code></pre>

<p>BeamFileActivity: This is a separate activity that just displays instructions for beaming the data and does the actual beam.</p>

<pre><code>private void initFileToBeam(Long spreadsheetId) {

    try {

        List&lt;SpreadsheetDom&gt; spreadsheets = db.getSpreadsheetDao().queryForEq(SpreadsheetDom.SPREADSHEET_ID_NAME, spreadsheetId);
        if(spreadsheets != null &amp;&amp; spreadsheets.size() &gt; 0) {

            fileToBeam = spreadsheets.get(0);
        }
    } catch(SQLException e) {

        ErrorDialog ed = new ErrorDialog(this, "Unable to beam current collection.");
        ed.show();
    }
}

@Override
public NdefMessage createNdefMessage(NfcEvent event) {

    if(fileToBeam == null) {

        Long spreadsheetId = Settings.getInstance().get(SettingKey.CURRENT_SPREADSHEET).getValue();
        initFileToBeam(spreadsheetId);
    }

    NdefMessage msg = null;
    try {

        msg = new NdefMessage(
                new NdefRecord[]{
                        new NdefRecord(NdefRecord.TNF_EXTERNAL_TYPE, "application/com.myapp:SpreadsheetDom".getBytes(), new byte[0], fileToBeam.toBytes()),
                        //NdefRecord.createExternal("com.myapp", "spreadsheetdom", fileToBeam.toBytes()),
                        NdefRecord.createApplicationRecord("com.myapp")
                });
    } catch(IOException e) {

        String textMessage = "Unable to transfer collection: " + e.getMessage();
        msg = new NdefMessage(
                new NdefRecord[]{
                        NdefRecord.createMime("text/plain", textMessage.getBytes()),
                        NdefRecord.createApplicationRecord("com.myapp")
                });
    }

    return msg;
}

@Override
public void onResume() {

    super.onResume();

    Intent exportFileIntent = getIntent();
    Long spreadsheetId = exportFileIntent.getLongExtra(Constants.EXTRA_SPREADSHEET_ID, Database.INVALID_ID);

    initFileToBeam(spreadsheetId);

    mNfcAdapter = NfcAdapter.getDefaultAdapter(this);
    if (mNfcAdapter == null) {

        Toast.makeText(this, "NFC is not available", Toast.LENGTH_LONG).show();
        finish();
        return;
    }
    // Register callback
    mNfcAdapter.setNdefPushMessageCallback(this, this);
}
</code></pre>

<p>Really all of this is from the examples and documentation <a href="https://android.googlesource.com/platform/development/+/2f33e1eae0671cc1aa3d367f8d900b532f6ca80f/samples/AndroidBeamDemo/src/com/example/android/beam/Beam.java" rel="nofollow">here</a>, <a href="https://developer.android.com/guide/topics/connectivity/nfc/nfc.html" rel="nofollow">here</a> and <a href="https://developer.android.com/training/beam-files/send-files.html" rel="nofollow">here</a></p>