{"action":"closed","issue":{"url":"https://api.github.com/repos/chariotsolutions/phonegap-nfc/issues/217","repository_url":"https://api.github.com/repos/chariotsolutions/phonegap-nfc","labels_url":"https://api.github.com/repos/chariotsolutions/phonegap-nfc/issues/217/labels{/name}","comments_url":"https://api.github.com/repos/chariotsolutions/phonegap-nfc/issues/217/comments","events_url":"https://api.github.com/repos/chariotsolutions/phonegap-nfc/issues/217/events","html_url":"https://github.com/chariotsolutions/phonegap-nfc/issues/217","id":122249153,"node_id":"MDU6SXNzdWUxMjIyNDkxNTM=","number":217,"title":"Android: addNdefListener not calling callback on first attempt","user":{"login":"homer-jay","id":5468827,"node_id":"MDQ6VXNlcjU0Njg4Mjc=","avatar_url":"https://avatars0.githubusercontent.com/u/5468827?v=4","gravatar_id":"","url":"https://api.github.com/users/homer-jay","html_url":"https://github.com/homer-jay","followers_url":"https://api.github.com/users/homer-jay/followers","following_url":"https://api.github.com/users/homer-jay/following{/other_user}","gists_url":"https://api.github.com/users/homer-jay/gists{/gist_id}","starred_url":"https://api.github.com/users/homer-jay/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/homer-jay/subscriptions","organizations_url":"https://api.github.com/users/homer-jay/orgs","repos_url":"https://api.github.com/users/homer-jay/repos","events_url":"https://api.github.com/users/homer-jay/events{/privacy}","received_events_url":"https://api.github.com/users/homer-jay/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":4,"created_at":"2015-12-15T11:14:02Z","updated_at":"2018-06-01T20:37:33Z","closed_at":"2018-06-01T20:37:33Z","author_association":"CONTRIBUTOR","body":"# Description\n\nIn Android, `addNdefListener` is not calling the callback on the first attempt. Any successive call works ok.\n\nI've debugged the plugin java source code, and placed breakpoints in the `parseMessage` method. In the first tag read, the action is `ACTION_NDEF_DISCOVERED`, while every succesive read over the same tag produces an `ACTION_TECH_DISCOVERED` action. The plugin class fires a \"ndef-mime\" event in the first case, and regular \"ndef\" events for every successive tag read. As a consecuence of this, the callback for `addNdefListener` is not fired for the first attempt, since these are only relayed to callbacks registered with `addMimeTypeListener` instead.\n\nThis was tested using Cordova v3.7.2.\n\nAdding \n`<param name=\"onload\" value=\"true\" />`\n to the res/config.xml file did not fix the issue.\n# Steps to reproduce\n\nSelect a tag that your phone supports. Write a single plain text record (not MIME, just a WELL_KNOWN of type T)\nYou can use any external app to verify and write the tags (e.g.: NXP's TagInfo and TagWriter are free to download from Google Play).\n\nthen in your Cordova app, run the following javascript:\n\n``` javascript\nwindow.nfc.addNdefListener(\n    function(){\n        console.log(\"Tag detected\");\n    },\n    function(){\n        console.log(\"listener registered\");\n    },\n    function(e){\n        console.error(\"Error registering listener: \" + e);\n    }\n);\n```\n\nDo not register any other listener.\n# Expected result\n\nThe \"Tag detected\" line should be logged each time a properly formatted NDEF tag is read.\n# Actual result:\n\nIn the first attempt the plugin doesn't notify the callback even though it has detected the tag and logged the event. Consecutive reads over the very same tag work fine, and the \"Tag detected\" line is logged.\n# Examples:\n\n**TEST 1**\nDevice: Samsung Galaxy S3 Mini\nOS: 4.1.2\nTag type: Mifare Classic\n\nFirst attempt log:\n`var e = document.createEvent('Events');\n    e.initEvent('ndef-mime');\n    e.tag = {\"isWritable\":true,\"id\":[12,31,18,17],\"techTypes\":[\"android.nfc.tech.NfcA\",\"android.nfc.tech.MifareClassic\",\"android.nfc.tech.Ndef\"],\"type\":\"NFC Forum Type 2\",\"canMakeReadOnly\":true,\"maxSize\":716,\"ndefMessage\":[{\"id\":[],\"type\":[84],\"payload\":[2,101,115,104,101,108,108,111],\"tnf\":1}]};\n    document.dispatchEvent(e);`\n\nSuccesive attempts log:\n`var e = document.createEvent('Events');\n    e.initEvent('ndef');\n    e.tag = {\"isWritable\":true,\"id\":[12,31,18,17],\"techTypes\":[\"android.nfc.tech.NfcA\",\"android.nfc.tech.MifareClassic\",\"android.nfc.tech.Ndef\"],\"type\":\"NFC Forum Type 2\",\"canMakeReadOnly\":true,\"maxSize\":716,\"ndefMessage\":[{\"id\":[],\"type\":[84],\"payload\":[2,101,115,104,101,108,108,111],\"tnf\":1}]};\n    document.dispatchEvent(e);`\n\n**TEST 2**\nDevice: Samsung Galaxy Core Prime LTE\nOS: 4.4.4\nTag type: ICODE SLIX\n\nFirst attempt log:\n`var e = document.createEvent('Events');\n    e.initEvent('ndef-mime');\n    e.tag = {\"isWritable\":true,\"id\":[-31,-96,70,0,80,1,4,-32],\"techTypes\":[\"android.nfc.tech.NfcV\",\"android.nfc.tech.Ndef\"],\"type\":\"android.ndef.unknown\",\"canMakeReadOnly\":false,\"maxSize\":106,\"ndefMessage\":[{\"id\":[],\"type\":[84],\"payload\":[2,101,115,104,101,108,108,111],\"tnf\":1}]};\n    document.dispatchEvent(e);`\n\nSuccesive attempts log:\n`var e = document.createEvent('Events');\n    e.initEvent('ndef');\n    e.tag = {\"isWritable\":true,\"id\":[-31,-96,70,0,80,1,4,-32],\"techTypes\":[\"android.nfc.tech.NfcV\",\"android.nfc.tech.Ndef\"],\"type\":\"android.ndef.unknown\",\"canMakeReadOnly\":false,\"maxSize\":106,\"ndefMessage\":[{\"id\":[],\"type\":[84],\"payload\":[2,101,115,104,101,108,108,111],\"tnf\":1}]};\n    document.dispatchEvent(e);`\n\n**TEST 3**\nDevice: Samsung Galaxy A3\nOS: 5.0.2\nTag type: ICODE SLIX\n\nResult: same as previous tests.\n\n**TEST 4**\nDevice: Huawei Ascend G300\nOS: 4.0.3\nTag type: ICODE SLIX\n\nResult: same as previous tests.\n"}}
{"actor":{"display_login":"don"}}