6

I was able to send a file using NFC, based on tutorials on the Android developer site. However I'm unable to handle the receiver part.

I follow http://developer.android.com/training/beam-files/receive-files.html for the receiving side and I get the notification that the Beam file transfer was successful on the receiver. When the user clicks this notification, I expect the that my app should be launched.

My receiving activity has the following intent filters:

<intent-filter>
 <action android:name="android.intent.action.VIEW"/>
 <category android:name="android.intent.category.DEFAULT"/>
 <data android:mimeType="image/*" />
 <data android:mimeType="video/*" />
 <data android:scheme="file" />
</intent-filter>

But my receiving activity never gets called even the file transfer was finished. How can I receive the file in my app?

Michael Roland
  • 39,663
  • 10
  • 99
  • 206
user3847939
  • 101
  • 4
  • Why do you think that your activity shoyld get started? There is nothing in the intent with something from NFC. – greenapps Jun 17 '15 at 09:00
  • When the user clicks the notification that beam transfer is success then my app should be launched. Here's what I am trying to do. http://developer.android.com/training/beam-files/receive-files.html – user3847939 Jun 17 '15 at 09:21

1 Answers1

0

From Receiving Files from Another Device:

Note: For Android Beam file transfer, you receive a content URI in the ACTION_VIEW intent if the first incoming file has a MIME type of "audio/*", "image/*", or "video/*", indicating that the file is media- related.

Due to the way how <data ... /> filters are processed (see Data Test and Data Element), your intent filter translates to

  • intent action VIEW and MIME type "image/*" and URI with scheme "file:", or
  • intent action VIEW and MIME type "video/*" and URI with scheme "file:".

So it must match any of the MIME types and any of the URIs that are given in the data element(s)..

Consequently your intent filter can never match as both, the "image/*" MIME type and the "video/*" MIME type will result in a content URI and not a "file:" URI. Hence, either skipping the URI filter part or chaging the filtered scheme to "content" should do the trick.

<intent-filter>
    <action android:name="android.intent.action.VIEW"/>
    <category android:name="android.intent.category.DEFAULT"/>
    <data android:mimeType="image/*" />
    <data android:mimeType="video/*" />
</intent-filter>

or

<intent-filter>
    <action android:name="android.intent.action.VIEW"/>
    <category android:name="android.intent.category.DEFAULT"/>
    <data android:mimeType="image/*" />
    <data android:mimeType="video/*" />
    <data android:scheme="content" />
</intent-filter>
Michael Roland
  • 39,663
  • 10
  • 99
  • 206