[TIMOB-25776] Android: Cannot use Ti.NFC
GitHub Issue | n/a |
Type | Bug |
Priority | Critical |
Status | Closed |
Resolution | Done |
Resolution Date | 2018-03-10T09:16:07.000+0000 |
Affected Version/s | Release 7.0.1 |
Fix Version/s | n/a |
Components | Android |
Labels | activity, launchmode, nfc |
Reporter | Daniel Falcon |
Assignee | Gary Mathews |
Created | 2018-01-29T13:31:11.000+0000 |
Updated | 2018-08-06T17:34:48.000+0000 |
Description
Dear all,
I've been playing (or trying to play) with the ti.nfc module for a while.
I'm just throwing there the example TagViewer from the module examples, just a copy and paste of the module and a modification of the tiapp.xml to add the android properties in manifest.
However, when trying to run the project, this warning appears in there:
[WARN] : android:launchMode should not be used. Ignoring definition from .NfcActivity
And the application doesn't work properly. Am I doing something wrong? Should I change something to allow android:launchMode?
Thanks for your comments.
PD: I've also attached the tiapp.xml the modules folder and the app folder of the project, in case you want to take a look (I tried to attach the whole project, but looks like it is too heavy).
Attachments
File | Date | Size |
app.zip | 2018-01-29T13:29:16.000+0000 | 1498675 |
modules.zip | 2018-01-29T13:30:11.000+0000 | 7771071 |
tiapp.xml | 2018-01-29T13:28:59.000+0000 | 4202 |
Hello, follow guide in http://docs.appcelerator.com/platform/latest/#!/api/Modules.Nfc "android:launchMode="singleTask" is needed so that new intents that result from NFC message dispatching do not start a new activity in your application." Thanks.
Dear Sharif, If you look at the attached tiapp.xml, I have the android:launchMode="singleTask" already added
But when packaging the app, the log says: [WARN] : android:launchMode should not be used. Ignoring definition from .NfcActivity And thus, android:launchMode="singleTask" cannot be used. Can you please take a look why? Thanks.
I've also tested a possible solution that I've found on some Github issues, that is adding the following code to the alloy.js file:
But this is also NOT working. Please help, I have a major business opportunity if I can integrate NFC in my apps. Thanks.
Hello [~dfalcon], Thanks for your feedback. *NFC module* is allowing applications to read and write (Android-only) NFC tags. Are you able to do this by using your application? Please let us know.
Mostafizur, Again, this is failing due to the impossibility to use android:launchMode. I have built a very simple NFC app in Android Studio that works without problem, so there is something wrong in Appcelerator. I have provided an alloy example in the ticket for you to check and test. Please check it and provide an explanation on how to make android:launchMode work in Appcelerator. An example app with NFC that works will also work and will help to all the users struggling with the same problem. Thanks.
Hello, Can you use the only the "android:launchMode="singleTask"" with out the "android:label="NFC"" as in the docs trap.xml section? Thanks.
Hi Sharif, I did as indicated, and it's still the same: [WARN] : android:launchMode should not be used. Ignoring definition from .NfcActivity And the app doesn't work. The manifest looks like this now:
http://docs.appcelerator.com/platform/latest/#!/guide/Android_Intent_Filters-section-src-43287610_AndroidIntentFilters-LaunchMode
Hi Gary, I'm a bit confused here. First, Sharif tell me to "follow guide in http://docs.appcelerator.com/platform/latest/#!/api/Modules.Nfc "android:launchMode="singleTask" is needed so that new intents that result from NFC message dispatching do not start a new activity in your application." In module NFC (latest version) and in the appcelerator documentation is stated that "android:launchMode="singleTask" should be used and is needed to make the NFC app work. Then, you point me to a section of the documentation where is stated that "launch modes cannot be used with Titanium Android". Isn't that contradictory? I have also tried the workaround of
and it does exactly the same: the app doesn't work. When scanning a tag, the app re-opens and nothing is scanned. Please, take a real look at this. There are many users struggling to make this work and I know of some that are leaving appcelerator due to this kind of unsolved problems. As appcelerator engineers I think that the best approach would be to provide a working solution for this problem instead to pointing to a faulty documentation that "will be taken down in the near future". Thanks for helping.
Hello [~dfalcon], Titanium does not support "singleTask" mode. With the way Titanium is currently architected, there is no way to make that mode work. It would end up getting stuck on the splash screen if you tried to use it. The NFC doc is wrong and needs to be updated. Since launch modes cannot be used with Titanium Android, to offer similar behaviour to android:launchMode= "singleTask" when using intent filters, you can set the intent-filter-new-task property in your tiapp.xml. See docs: http://docs.appcelerator.com/platform/latest/#!/guide/Android_Intent_Filters Please try it and let us know the result. Thanks.
Sharif, Did you read my previous comment? I have already tried that workaround without success. I feel like you aren't even trying... Again, providing a working example (a really working example) should be the best way to address this, and also for you to investigate an know how to correct the documents and the SDK in order to make this work.
Hey [~dfalcon]! We discussed this internally and the docs are indeed outdated on Ti.NFC. We will prepare an NFC example that works with newer versions of the SDK and update the docs afterwards. Please allow us to investigate and come back to you once we have something for you. Thanks!
Hi Hans, Do you have any feedback to share or a rough date for this? I'm eager to have this working, so I can avoid any more bottlenecks in the schedule of my projects. Thanks for the information!
Hey [~dfalcon], our Android team currently finishes the last touches on the 7.1.0 release, please allow us to come back to you soon afterwards.
[~dfalcon] Have you tried the other examples from the modules if they were working? Also information about the device(s) you are using will be helpful. Any info you can share would be helpful.
Hi Yordan, Yes, I have tried the other examples, even with SDK 7.0.2 and I'm still experiencing the same issues. In the months I've been trying to make this work I've tested in several devices, some huawei, some sansung and other brands. Now I have at hand a Huawei P8 Lite and a Huawei 10 pro for testing, both with the same issues. Have you managed to make an android app run in SDK 7.0.2? If so, can you share a working example? If you read the rest of the issue ticket, you'll see that I've tested all the provided workarounds, and yet I still have the same issues. Here, you have also what I've done so far and the results.
[~dfalcon] Are you trying to scan a NFC chip or communicate between two devices through Android Beam? The Beam examples from the module worked just fine between Huawei P8 Lite and Samsung S8. If you get any error logs or warning, please share them.
Yordan, Sorry for the late answer. I wasn't aware you answerd this. This is what I got for each example: *TAGWRITER*: Without android:launchMode, and with property intent-filter-new-task set to true
Same behaviour with android:launchMode and also:
*TAGVIEWER*: Without android:launchMode, and with property intent-filter-new-task set to true No errors: The app just reopens itself and nothing is scanned Same behaviour with android:launchMode and:
*TAGFOREGROUND*: Without android:launchMode, and with property intent-filter-new-task set to true
Same behaviour with android:launchMode and, as usual:
*TAGBEAMURIS*: With and without android:launchMode: When pressing “select type of message to send”, nothing happens and this error appears (I've tryied to put a flower.jpg image in almost all the folders of the project):
*TAGBEAM*: With and without android:launchMode: No matter which option I select from the list (text, uri, media, etc) the other phone doesn’t detect it. Also when trying to beam Media, this error appears (there is a defaults.png image in the Resources folder).
I've been unable to run any of the samples. Even trying lots of modifications and possible workarounds nothing seems to work. If this works for you, please share how did you do it and maybe your code and your tiapp.xml, so we can see what are we doing wrong. Please help EDIT: I'm trying to read/write a Tag and also another NFC enabled device. The Tag is perfectly readable by other Play Store apps and also from a simple app that I made using Android Studio. UPDATE: Tested this morning in SDK 7.1.0.RC as per indication of the support team. Exactly the same issues as with previous SDKs.
[~dfalcon] What does your tiapp.xml look like? These are the intent-filters I used:
I made a basic example of detecting tags here:
After scanning an NFC card I receive an alert dialog on the screen.
Hi Gary, My tiapp.xml is attached at the beginning of the ticket. So, should I get rid of the alloy examples and try to do this in a classic project? Should I add or remove something from my tiapp.xml? I think that, at least, the intent for the "android.nfc.action.TAG_DISCOVERED" is not in there. So, for my next "experiment": Should I get rid of the android:launchMode="singleTask" and add the
Ah yes, so I found it's important to define
in each
intent-filter
. You can use either Alloy or Classic, I personally prefer working with classic projects. But this shouldn't make a difference. Setting anyandroid:launchMode
parameters will be ignored. I also found I didn't need to specifyintent-filter-new-task
for this to work. Try my example code and see if that works for you?Finally. After adding your adjustments on a classic project the tag scanning worked. I've even managed to make the app write in the tag using part of the code from the old examples (without the foreground dispatchers and all). I think that the problem was both the lack of the TAG_DISCOVERED intent plus a wrong coding in the alloy examples, probably outdated since SDK 6.0.4 or so. This is working now on SDK 7.1.0.RC. I will be doing more test with the rest of possibilities (beam) as soon as I get back to my office, but this looks promising. Many thanks for the effort on checking this. For the community, I think it will be worthy to update the documentation on Ti.NFC to allow the usage of the module without any difficulties (in fact, how it works right now is even easier than in the old examples).
Happy to hear that [~dfalcon]! I've [updated the docs](https://github.com/appcelerator-modules/ti.nfc/commit/89f7c621bffc85046457ace77218f67acc9349af) to reflect the intent-configuration and will do the same for the example. We should also add an example to the KitchenSink (cc [~topener]). *EDIT*: [~bimmel] The docs of the NFC module have been updated. Can we include these changes in the Mondays docs push as well or are they automatically fetched anyway?
[~hknoechel], I'll push this change out during our next release.
Hi guys, Hate to bring this to the table again, but I found a possible bug on the module. Whenever you scan a tag, the app starts a new activity, and there is no way to create an app running in single activity. The documentation stated that "android:launchMode='singleTask' is needed so that new intents that result from NFC message dispatching do not start a new activity in your application". As this is not working anymore, the workaround the get the same behaviour, according to more up-to-date documentation, is to use the
I've also seen that there is an example that uses something called "Foreground Dispatching". However, when I try to use the code of that example, I always found the following errors:
For reference, I'm using this code in a classic project:
With the help of Gary I could make NFC apps that read, write, beam or receive. But always with the app getting a new activity. Could you help me to understand how should I use Foreground Dispatching to avoid the app creating a new Activity each time it scans an NFC Tag or a Beam?
Closed as completed. If this is in error, please reopen.