How to receive file using NFC (Android Beam) in Android
Asked Answered
P

1

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?

Protomartyr answered 17/6, 2015 at 7:12 Comment(2)
Why do you think that your activity shoyld get started? There is nothing in the intent with something from NFC.Welbie
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. developer.android.com/training/beam-files/receive-files.htmlProtomartyr
W
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>
Wonderful answered 17/6, 2015 at 18:32 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.