Dear fellow Developers
New at Ti.Alloy ... new at JS ... teaching myself via tutorials and examples. New subject is NFC. I've built two apps that have both reverted or hung up at Splash Screen. I've searched most forums but no resolution yet. The most recent is the the example by Jeff English : https://github.com/appcelerator-modules/ti.nfc/tree/master/android/example/TagViewer that I'm working through. This app runs well but once a tag is read the app reverts almost immediately from the data display View to the Splash Screen and has to be re-launched.
Host PC on Windows 7 / Titanium SDK 3.2.3 / Titanium Studio 3.2.3.201404181442 / Device Android S4 Mini via USB.
Here is the tiapp.xml :
<?xml version="1.0" encoding="UTF-8"?> <ti:app xmlns:ti="http://ti.appcelerator.org"> <id>com.ssa.TagViewer</id> <name>TagViewer</name> <version>1.0</version> <publisher>William</publisher> <url>http://</url> <description>not specified</description> <copyright>2014 by William</copyright> <icon>appicon.png</icon> <fullscreen>false</fullscreen> <navbar-hidden>false</navbar-hidden> <analytics>true</analytics> <guid>b195cd1b-d18f-4548-ae96-a88438a1fc33</guid> <property name="ti.ui.defaultunit" type="string">dp</property> <ios> <plist> <dict> <key>UISupportedInterfaceOrientations~iphone</key> <array> <string>UIInterfaceOrientationPortrait</string> </array> <key>UISupportedInterfaceOrientations~ipad</key> <array> <string>UIInterfaceOrientationPortrait</string> <string>UIInterfaceOrientationPortraitUpsideDown</string> <string>UIInterfaceOrientationLandscapeLeft</string> <string>UIInterfaceOrientationLandscapeRight</string> </array> <key>UIRequiresPersistentWiFi</key> <false/> <key>UIPrerenderedIcon</key> <false/> <key>UIStatusBarHidden</key> <false/> <key>UIStatusBarStyle</key> <string>UIStatusBarStyleDefault</string> </dict> </plist> </ios> <android xmlns:android="http://schemas.android.com/apk/res/android"> <manifest> <application> <activity android:configChanges="keyboardHidden|orientation" android:label="TagViewer" android:launchMode="singleTask" android:name=".TagviewerActivity" 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> <mobileweb> <precache/> <splash> <enabled>true</enabled> <inline-css-images>true</inline-css-images> </splash> <theme>default</theme> </mobileweb> <modules> <module platform="android">ti.nfc</module> </modules> <deployment-targets> <target device="iphone">false</target> <target device="ipad">false</target> <target device="android">true</target> <target device="blackberry">false</target> <target device="mobileweb">true</target> <target device="tizen">false</target> </deployment-targets> <sdk-version>3.2.3.GA</sdk-version> <plugins> <plugin version="1.0">ti.alloy</plugin> </plugins> </ti:app>Here is index.js :
var nfc = require('ti.nfc'); var nfcAdapter = null; $.index.addEventListener('open', function(e) { // Must wait until the activity has been opened before setting up NFC setupNfc(); }); // Force the instructions into the data area onClear({}); $.index.open(); function setupNfc() { // Create the NFC adapter to be associated with this activity. // There should only be ONE adapter created per activity. nfcAdapter = nfc.createNfcAdapter({ onNdefDiscovered: handleDiscovery, onTagDiscovered: handleDiscovery, onTechDiscovered: handleDiscovery }); // It's possible that the device does not support NFC. Check it here // before we go any further. if (!nfcAdapter.isEnabled()) { alert('NFC is not enabled on this device'); return; } // All tag scans are received by the activity as a new intent. Each // scan intent needs to be passed to the nfc adapter for processing. var act = Ti.Android.currentActivity; act.addEventListener('newintent', function(e) { nfcAdapter.onNewIntent(e.intent); }); } function handleDiscovery(e) { // Add rows for the message, tag, and each of the records var data = []; data.push(Alloy.createController('rowMessage', { action: e.action }).getView()); data.push(Alloy.createController('rowTag', { tag: e.tag }).getView()); if (e.messages) { var message = e.messages[0]; if (message.records) { var i, len; for (i=0, len=message.records.length; i<len; i++) { data.push(Alloy.createController('rowRecord', { record: message.records[i] }).getView()); } } } $.instructions.zIndex = -10000; $.records.setData(data); }; function onClear(e) { $.records.setData([]); $.instructions.zIndex = 10000; }Here is rowMessage.js :
var args = arguments[0] || {}; $.action.text = args.action.replace('android.nfc.action.', '');Here is rowRecord.js :
var args = arguments[0] || {}; $.recordType.text = args.record.recordType; $.tagData.value = JSON.stringify(args.record, function(key, value) { if(key === 'source') { return undefined; } else { return value; } }, 2);Here is rowTag.js :
var args = arguments[0] || {}; $.tagId.text = args.tag.id; $.techList.text = args.tag.techList.join("\n").replace(/android.nfc.tech./g, '');
Your help would be most appreciated .. I've had a very frustrating learning curve.
KR.