Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-25776] Android: Cannot use Ti.NFC

GitHub Issuen/a
TypeBug
PriorityCritical
StatusClosed
ResolutionDone
Resolution Date2018-03-10T09:16:07.000+0000
Affected Version/sRelease 7.0.1
Fix Version/sn/a
ComponentsAndroid
Labelsactivity, launchmode, nfc
ReporterDaniel Falcon
AssigneeGary Mathews
Created2018-01-29T13:31:11.000+0000
Updated2018-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

FileDateSize
app.zip2018-01-29T13:29:16.000+00001498675
modules.zip2018-01-29T13:30:11.000+00007771071
tiapp.xml2018-01-29T13:28:59.000+00004202

Comments

  1. Sharif AbuDarda 2018-01-29

    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.
  2. Daniel Falcon 2018-01-29

    Dear Sharif, If you look at the attached tiapp.xml, I have the android:launchMode="singleTask" already added
       <android xmlns:android="http://schemas.android.com/apk/res/android">
               <manifest>
                   <application>
                       <activity
                           android:configChanges="keyboardHidden|orientation"
                           android:label="NFC" android:launchMode="singleTask"
                           android:name=".NfcActivity" android:theme="@style/Theme.Titanium">
                           <intent-filter>
                               <action android:name="android.intent.action.MAIN"/>
                               <category android:name="android.intent.category.LAUNCHER"/>
                           </intent-filter>
                           <intent-filter>
                               <action android:name="android.nfc.action.NDEF_DISCOVERED"/>
                               <category android:name="android.intent.category.DEFAULT"/>
                               <data android:mimeType="text/plain"/>
                           </intent-filter>
                           <intent-filter>
                               <action android:name="android.nfc.action.NDEF_DISCOVERED"/>
                               <category android:name="android.intent.category.DEFAULT"/>
                               <data android:scheme="http"/>
                           </intent-filter>
                       </activity>
                   </application>
               </manifest>
           </android>
       
    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.
  3. Daniel Falcon 2018-01-29

    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:
       if (OS_ANDROID) {
         function resumeLauncher() {
           Alloy.createController('index', {
           });
         }
       
         if (Ti.Android.currentActivity) {
           Ti.Android.currentActivity.setOnResume(resumeLauncher)
         }
       }
       
    But this is also NOT working. Please help, I have a major business opportunity if I can integrate NFC in my apps. Thanks.
  4. Mostafizur Rahman 2018-01-30

    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.
  5. Daniel Falcon 2018-01-30

    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.
  6. Sharif AbuDarda 2018-01-30

    Hello, Can you use the only the "android:launchMode="singleTask"" with out the "android:label="NFC"" as in the docs trap.xml section? Thanks.
  7. Daniel Falcon 2018-01-30

    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:
           <android xmlns:android="http://schemas.android.com/apk/res/android">
               <manifest>
                   <application>
                       <activity
                           android:configChanges="keyboardHidden|orientation"
                           android:launchMode="singleTask"
                           android:name=".NfcActivity" android:theme="@style/Theme.Titanium">
                           <intent-filter>
                               <action android:name="android.intent.action.MAIN"/>
                               <category android:name="android.intent.category.LAUNCHER"/>
                           </intent-filter>
                           <intent-filter>
                               <action android:name="android.nfc.action.NDEF_DISCOVERED"/>
                               <category android:name="android.intent.category.DEFAULT"/>
                               <data android:mimeType="text/plain"/>
                           </intent-filter>
                           <intent-filter>
                               <action android:name="android.nfc.action.NDEF_DISCOVERED"/>
                               <category android:name="android.intent.category.DEFAULT"/>
                               <data android:scheme="http"/>
                           </intent-filter>
                       </activity>
                   </application>
               </manifest>
           </android>
       
  8. Gary Mathews 2018-01-31

    http://docs.appcelerator.com/platform/latest/#!/guide/Android_Intent_Filters-section-src-43287610_AndroidIntentFilters-LaunchMode
  9. Daniel Falcon 2018-01-31

    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
    <property name="intent-filter-new-task" type="bool">true</property>
    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.
  10. Sharif AbuDarda 2018-02-12

    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.
  11. Daniel Falcon 2018-02-12

    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.
  12. Hans Knöchel 2018-02-14

    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!
  13. Daniel Falcon 2018-02-22

    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!
  14. Hans Knöchel 2018-02-22

    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.
  15. Yordan Banev 2018-02-28

    [~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.
  16. Daniel Falcon 2018-03-01

    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.
  17. Yordan Banev 2018-03-02

    [~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.
  18. Daniel Falcon 2018-03-07

    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
        [WARN] :   W/System.err: java.lang.IllegalStateException: You must disable foreground dispatching while your activity is still resumed
        [WARN] :   W/System.err: 	at android.nfc.NfcAdapter.disableForegroundDispatchInternal(NfcAdapter.java:1345)
        [WARN] :   W/System.err: 	at android.nfc.NfcAdapter.disableForegroundDispatch(NfcAdapter.java:1331)
        [WARN] :   W/System.err: 	at ti.nfc.NfcAdapterProxy.handleDisableForegroundDispatch(NfcAdapterProxy.java:442)
        [WARN] :   W/System.err: 	at ti.nfc.NfcAdapterProxy.disableForegroundDispatch(NfcAdapterProxy.java:339)
        [WARN] :   W/System.err: 	at org.appcelerator.kroll.runtime.v8.V8Object.nativeFireEvent(Native Method)
        [WARN] :   W/System.err: 	at org.appcelerator.kroll.runtime.v8.V8Object.fireEvent(V8Object.java:62)
        [WARN] :   W/System.err: 	at org.appcelerator.kroll.KrollProxy.doFireEvent(KrollProxy.java:936)
        [WARN] :   W/System.err: 	at org.appcelerator.kroll.KrollProxy.handleMessage(KrollProxy.java:1159)
        [WARN] :   W/System.err: 	at org.appcelerator.titanium.proxy.ActivityProxy.handleMessage(ActivityProxy.java:362)
        [WARN] :   W/System.err: 	at android.os.Handler.dispatchMessage(Handler.java:98)
        [WARN] :   W/System.err: 	at android.os.Looper.loop(Looper.java:150)
        [WARN] :   W/System.err: 	at android.app.ActivityThread.main(ActivityThread.java:5621)
        [WARN] :   W/System.err: 	at java.lang.reflect.Method.invoke(Native Method)
        [WARN] :   W/System.err: 	at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:794)
        [WARN] :   W/System.err: 	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:684)
        [ERROR] :  TiExceptionHandler: (main) [75823,76040] ----- Titanium Javascript Runtime Error -----
        [ERROR] :  TiExceptionHandler: (main) [1,76041] - In /alloy/controllers/index.js:144,18
        [ERROR] :  TiExceptionHandler: (main) [0,76041] - Message: Uncaught You must disable foreground dispatching while your activity is still resumed
        [ERROR] :  TiExceptionHandler: (main) [0,76041] - Source:       nfcAdapter.disableForegroundDispatch();
        [ERROR] :  V8Exception: Exception occurred at /alloy/controllers/index.js:144: Uncaught You must disable foreground dispatching while your activity is still resumed
        [ERROR] :  V8Exception: You must disable foreground dispatching while your activity is still resumed
        
    Same behaviour with android:launchMode and also:
        [WARN] :   android:launchMode should not be used. Ignoring definition from .NfcActivity
        
    *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:
        [WARN] :   android:launchMode should not be used. Ignoring definition from .NfcActivity
        
    *TAGFOREGROUND*: Without android:launchMode, and with property intent-filter-new-task set to true
        [WARN] :   W/System.err: java.lang.IllegalStateException: You must disable foreground dispatching while your activity is still resumed
        [WARN] :   W/System.err: 	at android.nfc.NfcAdapter.disableForegroundDispatchInternal(NfcAdapter.java:1345)
        [WARN] :   W/System.err: 	at android.nfc.NfcAdapter.disableForegroundDispatch(NfcAdapter.java:1331)
        [WARN] :   W/System.err: 	at ti.nfc.NfcAdapterProxy.handleDisableForegroundDispatch(NfcAdapterProxy.java:442)
        [WARN] :   W/System.err: 	at ti.nfc.NfcAdapterProxy.disableForegroundDispatch(NfcAdapterProxy.java:339)
        [WARN] :   W/System.err: 	at org.appcelerator.kroll.runtime.v8.V8Object.nativeFireEvent(Native Method)
        [WARN] :   W/System.err: 	at org.appcelerator.kroll.runtime.v8.V8Object.fireEvent(V8Object.java:62)
        [WARN] :   W/System.err: 	at org.appcelerator.kroll.KrollProxy.doFireEvent(KrollProxy.java:936)
        [WARN] :   W/System.err: 	at org.appcelerator.kroll.KrollProxy.handleMessage(KrollProxy.java:1159)
        [WARN] :   W/System.err: 	at org.appcelerator.titanium.proxy.ActivityProxy.handleMessage(ActivityProxy.java:362)
        [WARN] :   W/System.err: 	at android.os.Handler.dispatchMessage(Handler.java:98)
        [WARN] :   W/System.err: 	at android.os.Looper.loop(Looper.java:150)
        [WARN] :   W/System.err: 	at android.app.ActivityThread.main(ActivityThread.java:5621)
        [WARN] :   W/System.err: 	at java.lang.reflect.Method.invoke(Native Method)
        [WARN] :   W/System.err: 	at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:794)
        [WARN] :   W/System.err: 	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:684)
        [ERROR] :  TiExceptionHandler: (main) [8161,13694] ----- Titanium Javascript Runtime Error -----
        [ERROR] :  TiExceptionHandler: (main) [2,13696] - In /alloy/controllers/index.js:138,18
        [ERROR] :  TiExceptionHandler: (main) [0,13696] - Message: Uncaught You must disable foreground dispatching while your activity is still resumed
        [ERROR] :  TiExceptionHandler: (main) [1,13697] - Source:       nfcAdapter.disableForegroundDispatch();
        [ERROR] :  V8Exception: Exception occurred at /alloy/controllers/index.js:138: Uncaught You must disable foreground dispatching while your activity is still resumed
        [ERROR] :  V8Exception: You must disable foreground dispatching while your activity is still resumed
        
    Same behaviour with android:launchMode and, as usual:
        [WARN] :   android:launchMode should not be used. Ignoring definition from .NfcActivity
        
    *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):
        [ERROR] :  TiFileProxy: (main) [594,594] IOException encountered
        [ERROR] :  TiFileProxy: java.io.FileNotFoundException: /storage/emulated/0/com.ASP.NFC/flower.jpg: open failed: ENOENT (No such file or directory)
        [ERROR] :  TiFileProxy: 	at libcore.io.IoBridge.open(IoBridge.java:459)
        [ERROR] :  TiFileProxy: 	at java.io.FileOutputStream.<init>(FileOutputStream.java:87)
        [ERROR] :  TiFileProxy: 	at org.appcelerator.titanium.io.TiFile.getOutputStream(TiFile.java:289)
        [ERROR] :  TiFileProxy: 	at org.appcelerator.titanium.io.TiFile.open(TiFile.java:352)
        [ERROR] :  TiFileProxy: 	at org.appcelerator.titanium.io.TiFile.write(TiFile.java:398)
        [ERROR] :  TiFileProxy: 	at org.appcelerator.titanium.TiFileProxy.write(TiFileProxy.java:307)
        [ERROR] :  TiFileProxy: 	at org.appcelerator.kroll.runtime.v8.V8Object.nativeFireEvent(Native Method)
        [ERROR] :  TiFileProxy: 	at org.appcelerator.kroll.runtime.v8.V8Object.fireEvent(V8Object.java:62)
        [ERROR] :  TiFileProxy: 	at org.appcelerator.kroll.KrollProxy.doFireEvent(KrollProxy.java:936)
        [ERROR] :  TiFileProxy: 	at org.appcelerator.kroll.KrollProxy.handleMessage(KrollProxy.java:1159)
        [ERROR] :  TiFileProxy: 	at org.appcelerator.titanium.proxy.TiViewProxy.handleMessage(TiViewProxy.java:363)
        [ERROR] :  TiFileProxy: 	at ti.modules.titanium.ui.PickerProxy.handleMessage(PickerProxy.java:331)
        [ERROR] :  TiFileProxy: 	at android.os.Handler.dispatchMessage(Handler.java:98)
        [ERROR] :  TiFileProxy: 	at android.os.Looper.loop(Looper.java:150)
        [ERROR] :  TiFileProxy: 	at android.app.ActivityThread.main(ActivityThread.java:5621)
        [ERROR] :  TiFileProxy: 	at java.lang.reflect.Method.invoke(Native Method)
        [ERROR] :  TiFileProxy: 	at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:794)
        [ERROR] :  TiFileProxy: 	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:684)
        [ERROR] :  TiFileProxy: Caused by: android.system.ErrnoException: open failed: ENOENT (No such file or directory)
        [ERROR] :  TiFileProxy: 	at libcore.io.Posix.open(Native Method)
        [ERROR] :  TiFileProxy: 	at libcore.io.BlockGuardOs.open(BlockGuardOs.java:186)
        [ERROR] :  TiFileProxy: 	at libcore.io.IoBridge.open(IoBridge.java:445)
        [ERROR] :  TiFileProxy: ... 17 more
        
    *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).
        [ERROR] :  TiBlob: (main) [1,164329] Resources/defaults.png
        [ERROR] :  TiBlob: java.io.FileNotFoundException: Resources/defaults.png
        [ERROR] :  TiBlob: 	at android.content.res.AssetManager.openAsset(Native Method)
        [ERROR] :  TiBlob: 	at android.content.res.AssetManager.open(AssetManager.java:560)
        [ERROR] :  TiBlob: 	at android.content.res.AssetManager.open(AssetManager.java:534)
        [ERROR] :  TiBlob: 	at org.appcelerator.titanium.io.TiResourceFile.getInputStream(TiResourceFile.java:77)
        [ERROR] :  TiBlob: 	at org.appcelerator.titanium.TiBlob.getInputStream(TiBlob.java:390)
        [ERROR] :  TiBlob: 	at org.appcelerator.titanium.TiBlob.loadBitmapInfo(TiBlob.java:285)
        [ERROR] :  TiBlob: 	at org.appcelerator.titanium.TiBlob.blobFromFile(TiBlob.java:140)
        [ERROR] :  TiBlob: 	at org.appcelerator.titanium.TiBlob.blobFromFile(TiBlob.java:113)
        [ERROR] :  TiBlob: 	at org.appcelerator.titanium.io.TiResourceFile.read(TiResourceFile.java:121)
        [ERROR] :  TiBlob: 	at org.appcelerator.titanium.TiFileProxy.read(TiFileProxy.java:257)
        [ERROR] :  TiBlob: 	at org.appcelerator.kroll.runtime.v8.V8Object.nativeFireEvent(Native Method)
        [ERROR] :  TiBlob: 	at org.appcelerator.kroll.runtime.v8.V8Object.fireEvent(V8Object.java:62)
        [ERROR] :  TiBlob: 	at org.appcelerator.kroll.KrollProxy.doFireEvent(KrollProxy.java:936)
        [ERROR] :  TiBlob: 	at org.appcelerator.kroll.KrollProxy.handleMessage(KrollProxy.java:1159)
        [ERROR] :  TiBlob: 	at org.appcelerator.titanium.proxy.TiViewProxy.handleMessage(TiViewProxy.java:363)
        [ERROR] :  TiBlob: 	at ti.modules.titanium.ui.PickerProxy.handleMessage(PickerProxy.java:331)
        [ERROR] :  TiBlob: 	at android.os.Handler.dispatchMessage(Handler.java:98)
        [ERROR] :  TiBlob: 	at android.os.Looper.loop(Looper.java:150)
        [ERROR] :  TiBlob: 	at android.app.ActivityThread.main(ActivityThread.java:5621)
        [ERROR] :  TiBlob: 	at java.lang.reflect.Method.invoke(Native Method)
        [ERROR] :  TiBlob: 	at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:794)
        [ERROR] :  TiBlob: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:684)
        
    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.
  19. Gary Mathews 2018-03-09

    [~dfalcon] What does your tiapp.xml look like? These are the intent-filters I used:
        <intent-filter>
        	<action android:name="android.nfc.action.TECH_DISCOVERED"/>
        	<category android:name="android.intent.category.DEFAULT"/>
        </intent-filter>
        
        <intent-filter>
        	<action android:name="android.nfc.action.NDEF_DISCOVERED"/>
        	<category android:name="android.intent.category.DEFAULT"/>
        	<data android:mimeType="text/plain" />
        </intent-filter>
        
        <intent-filter>
        	<action android:name="android.nfc.action.TAG_DISCOVERED"/>
        	<category android:name="android.intent.category.DEFAULT"/>
        </intent-filter>
        
        <uses-permission android:name="android.permission.NFC" />
        <uses-feature android:name="android.hardware.nfc" android:required="true" />
        
    I made a basic example of detecting tags here:
        var win = Ti.UI.createWindow({ backgroundColor: 'gray' }),
            nfc = require('ti.nfc'),
            nfcAdapter = nfc.createNfcAdapter({
                onNdefDiscovered: handleDiscovery,
                onTagDiscovered: handleDiscovery,
                onTechDiscovered: handleDiscovery
            });
        
        function handleDiscovery (e) {
            alert(JSON.stringify(e, null, 2));
        }
        
        if (!nfcAdapter.isEnabled()) {
            alert('NFC is not enabled on this device');
        } else {
            Ti.Android.currentActivity.addEventListener('newintent', function (e) {
                nfcAdapter.onNewIntent(e.intent);
            });
        }
        
        win.open();
        
    After scanning an NFC card I receive an alert dialog on the screen.
  20. Daniel Falcon 2018-03-09

    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 true ? If you can answer this I will perform some more tests as soon as possible and let you know the results. Thanks for helping.
  21. Gary Mathews 2018-03-09

    Ah yes, so I found it's important to define
        <category android:name="android.intent.category.DEFAULT"/>
        
    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 any android:launchMode parameters will be ignored. I also found I didn't need to specify intent-filter-new-task for this to work. Try my example code and see if that works for you?
  22. Daniel Falcon 2018-03-10

    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).
  23. Hans Knöchel 2018-03-10

    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?
  24. (deactived) Brian Immel 2018-03-12

    [~hknoechel], I'll push this change out during our next release.
  25. Daniel Falcon 2018-03-19

    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 true But even adding that, the app is still creating a new Activity. With each scan, the app shows a different activity name as shown:
        [INFO] :   TiRootActivity: (main) [0,0] checkpoint, on root activity create, savedInstanceState: null
        [INFO] :   TiRootActivity: (main) [0,0] checkpoint, on root activity resume. activity = com.dfa.zznfc.ZznfcActivity@c44e1ae
        [INFO] :   TiRootActivity: (main) [0,0] checkpoint, on root activity create, savedInstanceState: null
        [INFO] :   TiRootActivity: (main) [0,0] checkpoint, on root activity resume. activity = com.dfa.zznfc.ZznfcActivity@ff1dd2b
        [INFO] :   TiRootActivity: (main) [0,0] checkpoint, on root activity create, savedInstanceState: null
        [INFO] :   TiRootActivity: (main) [0,0] checkpoint, on root activity resume. activity = com.dfa.zznfc.ZznfcActivity@6b7e0e1
        
    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:
        [WARN] :   W/System.err: java.lang.IllegalStateException: Foreground dispatch can only be enabled when your activity is resumed
        [WARN] :   W/System.err: 	at android.nfc.NfcAdapter.enableForegroundDispatch(NfcAdapter.java:1298)
        [WARN] :   W/System.err: 	at ti.nfc.NfcAdapterProxy.handleEnableForegroundDispatch(NfcAdapterProxy.java:447)
        [WARN] :   W/System.err: 	at ti.nfc.NfcAdapterProxy.enableForegroundDispatch(NfcAdapterProxy.java:368)
        [WARN] :   W/System.err: 	at org.appcelerator.kroll.runtime.v8.V8Object.nativeFireEvent(Native Method)
        [WARN] :   W/System.err: 	at org.appcelerator.kroll.runtime.v8.V8Object.fireEvent(V8Object.java:63)
        [WARN] :   W/System.err: 	at org.appcelerator.kroll.KrollProxy.doFireEvent(KrollProxy.java:962)
        [WARN] :   W/System.err: 	at org.appcelerator.kroll.KrollProxy.handleMessage(KrollProxy.java:1186)
        [WARN] :   W/System.err: 	at org.appcelerator.titanium.proxy.ActivityProxy.handleMessage(ActivityProxy.java:374)
        [WARN] :   W/System.err: 	at android.os.Handler.dispatchMessage(Handler.java:98)
        [WARN] :   W/System.err: 	at android.os.Looper.loop(Looper.java:150)
        [WARN] :   W/System.err: 	at android.app.ActivityThread.main(ActivityThread.java:5621)
        [WARN] :   W/System.err: 	at java.lang.reflect.Method.invoke(Native Method)
        [WARN] :   W/System.err: 	at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:794)
        [WARN] :   W/System.err: 	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:684)
        [ERROR] :  TiExceptionHandler: (main) [206,206] ----- Titanium Javascript Runtime Error -----
        [ERROR] :  TiExceptionHandler: (main) [0,206] - In /app.js:54,14
        [ERROR] :  TiExceptionHandler: (main) [0,206] - Message: Uncaught Foreground dispatch can only be enabled when your activity is resumed
        [ERROR] :  TiExceptionHandler: (main) [1,207] - Source: 		nfcAdapter.enableForegroundDispatch(dispatchFilter);
        [ERROR] :  V8Exception: Exception occurred at /app.js:54: Uncaught Foreground dispatch can only be enabled when your activity is resumed
        [ERROR] :  V8Exception: Foreground dispatch can only be enabled when your activity is resumed
        [WARN] :   W/System.err: java.lang.IllegalStateException: You must disable foreground dispatching while your activity is still resumed
        [WARN] :   W/System.err: 	at android.nfc.NfcAdapter.disableForegroundDispatchInternal(NfcAdapter.java:1345)
        [WARN] :   W/System.err: 	at android.nfc.NfcAdapter.disableForegroundDispatch(NfcAdapter.java:1331)
        [WARN] :   W/System.err: 	at ti.nfc.NfcAdapterProxy.handleDisableForegroundDispatch(NfcAdapterProxy.java:442)
        [WARN] :   W/System.err: 	at ti.nfc.NfcAdapterProxy.disableForegroundDispatch(NfcAdapterProxy.java:339)
        [WARN] :   W/System.err: 	at org.appcelerator.kroll.runtime.v8.V8Object.nativeFireEvent(Native Method)
        [WARN] :   W/System.err: 	at org.appcelerator.kroll.runtime.v8.V8Object.fireEvent(V8Object.java:63)
        [WARN] :   W/System.err: 	at org.appcelerator.kroll.KrollProxy.doFireEvent(KrollProxy.java:962)
        [WARN] :   W/System.err: 	at org.appcelerator.kroll.KrollProxy.handleMessage(KrollProxy.java:1186)
        [WARN] :   W/System.err: 	at org.appcelerator.titanium.proxy.ActivityProxy.handleMessage(ActivityProxy.java:374)
        [WARN] :   W/System.err: 	at android.os.Handler.dispatchMessage(Handler.java:98)
        [WARN] :   W/System.err: 	at android.os.Looper.loop(Looper.java:150)
        [WARN] :   W/System.err: 	at android.app.ActivityThread.main(ActivityThread.java:5621)
        [WARN] :   W/System.err: 	at java.lang.reflect.Method.invoke(Native Method)
        [WARN] :   W/System.err: 	at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:794)
        [WARN] :   W/System.err: 	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:684)
        [ERROR] :  TiExceptionHandler: (main) [11,218] ----- Titanium Javascript Runtime Error -----
        [ERROR] :  TiExceptionHandler: (main) [0,218] - In /app.js:57,14
        [ERROR] :  TiExceptionHandler: (main) [0,218] - Message: Uncaught You must disable foreground dispatching while your activity is still resumed
        [ERROR] :  TiExceptionHandler: (main) [0,218] - Source: 		nfcAdapter.disableForegroundDispatch();
        [ERROR] :  V8Exception: Exception occurred at /app.js:57: Uncaught You must disable foreground dispatching while your activity is still resumed
        [ERROR] :  V8Exception: You must disable foreground dispatching while your activity is still resumed
        
    For reference, I'm using this code in a classic project:
        var win = Ti.UI.createWindow({ backgroundColor: 'gray' }),
            nfc = require('ti.nfc'),
            dispatchFilter,
            nfcAdapter = nfc.createNfcAdapter({
                onNdefDiscovered: handleDiscovery,
                onTagDiscovered: handleDiscovery,
                onTechDiscovered: handleDiscovery
            });
        function handleDiscovery (e) {
            alert(JSON.stringify(e, null, 2));
        }
        if (!nfcAdapter.isEnabled()) {
            alert('NFC is not enabled on this device');
        } else {
        	dispatchFilter = nfc.createNfcForegroundDispatchFilter({
        		intentFilters: [
        			// The discovery could be restricted to only text with
        			// { action: nfc.ACTION_NDEF_DISCOVERED, mimeType: 'text/plain' },
        			{ action: nfc.ACTION_NDEF_DISCOVERED, mimeType: '*/*' },
        			// The discovery could be restricted by host with
        			//{ action: nfc.ACTION_NDEF_DISCOVERED, scheme: 'http', host: 'www.appcelerator.com' }
        			{ action: nfc.ACTION_NDEF_DISCOVERED, scheme: 'http' }
        		],
        		// The techList can be specified to filter TECH_DISCOVERED messages by technology
        		techLists: [
        			[ "android.nfc.tech.NfcF" ],
        			[ "android.nfc.tech.Ndef" ],
        			[ "android.nfc.tech.MifareClassic" ],
        			[ "android.nfc.tech.NfcA" ]
        		]
        	});
                Ti.Android.currentActivity.addEventListener('newintent', function (e) {
                        nfcAdapter.onNewIntent(e.intent);
                });
        	Ti.Android.currentActivity.addEventListener('resume', function(e) {
        		nfcAdapter.enableForegroundDispatch(dispatchFilter);
        	});
        	Ti.Android.currentActivity.addEventListener('pause', function(e) {
        		nfcAdapter.disableForegroundDispatch();
        	});
        }
        win.open();
        
    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?
  26. Eric Merriman 2018-08-06

    Closed as completed. If this is in error, please reopen.

JSON Source