I want to send a text file and an image file from one device to another using Android Beam.
When the transfer is complete I want the receiving device to start a specific app that can import these two files.
This is how I got it to work using an NDEF message:
private static final String NDEF_DOMAIN_NAME = "my.app.domain";
private static final String NDEF_TYPE_NAME = "mytypename";
NdefRecord cardRecord = NdefRecord.createExternal(
NDEF_DOMAIN_NAME,
NDEF_TYPE_NAME,
textfile.getBytes());
NdefRecord cardImageRecord = NdefRecord.createExternal(
NDEF_DOMAIN_NAME,
NDEF_TYPE_NAME,
base64EncodedImage.getBytes());
NdefMessage ndefMessage = new NdefMessage(new NdefRecord[] { cardRecord, cardImageRecord });
mNfcAdapter.setNdefPushMessage(ndefMessage, activity);
But the transfer rate of "pure" NFC is of course much too slow for a whole image. So I have to use Android Beam with 2 file URIs:
Uri[] fileUris = new Uri[2];
fileUris[0] = pathToTextFile;
fileUris[1] = pathtoImageFile;
mNfcAdapter.setBeamPushUris(fileUris, activity);
The transfer works perfectly that way, but the receiving device does not start any app after receiving the files. I just get a notification that the transfer is complete. The manifest of the receiving app looks like this right now:
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="text/plain" />
</intent-filter>
That way I can at least select the app, when I click on the "transfer complete"-notification. But what I want would be something like this:
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<data android:mimeType="application/my-own-mime-type" />
</intent-filter>
This way my app would be the only app able to handle this mime-type. But I can't figure out how to set the mime-type on the sending device. Is this even possible or How can I transfer multiple files via Android Beam and open 1 specific app to handle these files?
UPDATE:
I just read here SO-question that a custom mime-type is not possible using Android Beam. It seems that the receiving device looks at the first file and its file ending to decide which mime-type to use for the ACTION_VIEW intent. Does anyone know if it's possible to zip all my files and then use a custom file ending instead of *.zip? Can I maybe create a fake mime-type that way?