{ "id": "171643", "key": "TIMOB-26029", "fields": { "issuetype": { "id": "1", "description": "A problem which impairs or prevents the functions of the product.", "name": "Bug", "subtask": false }, "project": { "id": "10153", "key": "TIMOB", "name": "Titanium SDK/CLI", "projectCategory": { "id": "10100", "description": "Titanium and related SDKs used in application development", "name": "Client" } }, "fixVersions": [], "resolution": { "id": "7", "description": "", "name": "Invalid" }, "resolutiondate": "2018-05-17T21:15:54.000+0000", "created": "2018-05-10T16:12:06.000+0000", "priority": { "name": "None", "id": "6" }, "labels": [], "versions": [ { "id": "20102", "name": "Release 7.1.1", "archived": false, "released": true, "releaseDate": "2018-05-02" } ], "issuelinks": [], "assignee": { "name": "jquick", "key": "jquick", "displayName": "Joshua Quick", "active": true, "timeZone": "America/Los_Angeles" }, "updated": "2018-08-06T17:37:03.000+0000", "status": { "description": "The issue is considered finished, the resolution is correct. Issues which are closed can be reopened.", "name": "Closed", "id": "6", "statusCategory": { "id": 3, "key": "done", "colorName": "green", "name": "Done" } }, "components": [ { "id": "10202", "name": "Android", "description": "Android Platform" } ], "description": "We want to detect the current state of headphones connected (true) or disconnected (false). We have an API for that but no example code in documents.\r\nhttp://docs.appcelerator.com/platform/latest/#!/api/Titanium.Android-property-ACTION_HEADSET_PLUG\r\nI create an example code but not working. \r\n{code}\r\nfunction doClick() {\r\n Ti.Android.unregisterBroadcastReceiver(bc);\r\n}\r\n$.index.open();\r\nvar onReceived = function(e) {\r\n Ti.API.info(\"received!\");\r\n Ti.API.info('Handling broadcast. >> ' + JSON.stringify(e));\r\n alert('Handling broadcast. >> ' + JSON.stringify(e));\r\n};\r\nvar bc = Ti.Android.createBroadcastReceiver({\r\n onReceived : onReceived\r\n});\r\nTi.Android.registerBroadcastReceiver(bc,[\"Titanium.Android.ACTION_HEADSET_PLUG\"]);\r\n{code}\r\nIndex.xml\r\n{code:xml}\r\n\r\n \r\n \r\n \r\n\r\n{code}\r\n\r\nTest Environment:\r\n{code}\r\nOperating System\r\n Name = Microsoft Windows 10 Pro\r\n Version = 10.0.16299\r\n Architecture = 32bit\r\n # CPUs = 4\r\n Memory = 17091956736\r\nNode.js\r\n Node.js Version = 8.9.1\r\n npm Version = 5.5.1\r\nTitanium CLI\r\n CLI Version = 5.1.0\r\nTitanium SDK\r\n SDK Version = 7.1.0.GA\r\n{code}\r\n\r\nThanks \r\n\r\n", "attachment": [], "flagged": false, "summary": "Android : Titanium.Android.ACTION_HEADSET_PLUG Not working as expected.", "creator": { "name": "aislam", "key": "aislam", "displayName": "Aminul Islam", "active": false, "timeZone": "Etc/GMT-6" }, "subtasks": [], "reporter": { "name": "aislam", "key": "aislam", "displayName": "Aminul Islam", "active": false, "timeZone": "Etc/GMT-6" }, "environment": "Operating System\r\n Name = Microsoft Windows 10 Pro\r\n Version = 10.0.16299\r\n Architecture = 32bit\r\n # CPUs = 4\r\n Memory = 17091956736\r\nNode.js\r\n Node.js Version = 8.9.1\r\n npm Version = 5.5.1\r\nTitanium CLI\r\n CLI Version = 5.1.0\r\nTitanium SDK\r\n SDK Version = 7.1.0.GA", "closedSprints": [ { "id": 1035, "state": "closed", "name": "2018 Sprint 11 SDK", "startDate": "2018-05-20T20:57:43.542Z", "endDate": "2018-06-03T20:57:00.000Z", "completeDate": "2018-06-04T15:13:14.425Z", "originBoardId": 114 } ], "comment": { "comments": [ { "id": "437742", "author": { "name": "cwilliams", "key": "cwilliams", "displayName": "Christopher Williams", "active": true, "timeZone": "America/New_York" }, "body": "Isn't this code example just wrong? The second argument to registerBroadcastReceiver should be an array of references to the Ti.Android.ACTION_* constants like so:\r\n{code:javascript}\r\nTi.Android.registerBroadcastReceiver(bc, [ Ti.Android.ACTION_HEADSET_PLUG ]);\r\n{code}\r\n\r\n\r\n(Note that {{Ti.Android.ACTION_HEADSET_PLUG}} is a reference to a constant whose value aliases to the correct String necessary under the hood, it itself is **not** a String)", "updateAuthor": { "name": "cwilliams", "key": "cwilliams", "displayName": "Christopher Williams", "active": true, "timeZone": "America/New_York" }, "created": "2018-05-17T19:25:29.000+0000", "updated": "2018-05-17T19:26:28.000+0000" }, { "id": "437746", "author": { "name": "jquick", "key": "jquick", "displayName": "Joshua Quick", "active": true, "timeZone": "America/Los_Angeles" }, "body": "This is not a bug.\r\n\r\nThe below code works. I've tested it on real devices running Android OS v4.1 and v8.0. When you connect/disconnect a headset to the Android device, it'll display a \"Connected\" or \"Disconnected\" label.\r\n\r\n{code:javascript}\r\n// Create a window with label displaying current headset state.\r\nvar window = Ti.UI.createWindow();\r\nvar label = Ti.UI.createLabel();\r\nwindow.add(label);\r\nwindow.open();\r\n\r\n// Register a headset broadcast receiver.\r\nvar receiver = Ti.Android.createBroadcastReceiver({\r\n\tonReceived: function(e) {\r\n\t\t// Headset has been connected/disconnected. Display current state via label.\r\n\t\tif (e.intent.action === Ti.Android.ACTION_HEADSET_PLUG) {\r\n\t\t\tvar isPluggedIn = (e.intent.getIntExtra(\"state\", 0) != 0);\r\n\t\t\tlabel.text = \"Headset is \" + (isPluggedIn ? \"Connected\" : \"Disconnected\");\r\n\t\t}\r\n\t},\r\n});\r\nTi.Android.registerBroadcastReceiver(receiver, [Ti.Android.ACTION_HEADSET_PLUG]);\r\n\r\n// Unregister above broadcast receiver when exiting.\r\nwindow.addEventListener(\"close\", function(e) {\r\n\tTi.Android.unregisterBroadcastReceiver(receiver);\r\n});\r\n{code}\r\n\r\nLike what Chris has said, they're incorrectly passing the {{Ti.Android.ACTION_HEADSET_PLUG}} constant in. They should not be double quoting it. For your info, Titanium's {{Ti.Android.ACTION_HEADSET_PLUG}} constant returns string {{\"android.intent.action.HEADSET_PLUG\"}}, which matches Google's constant here...\r\nhttps://developer.android.com/reference/android/content/Intent.html#ACTION_HEADSET_PLUG\r\n\r\nGoogle documents the intent \"extras\" for this action (such as \"state\") here...\r\nhttps://developer.android.com/reference/android/media/AudioManager#ACTION_HEADSET_PLUG\r\n", "updateAuthor": { "name": "jquick", "key": "jquick", "displayName": "Joshua Quick", "active": true, "timeZone": "America/Los_Angeles" }, "created": "2018-05-17T21:05:38.000+0000", "updated": "2018-05-17T21:05:38.000+0000" }, { "id": "439926", "author": { "name": "emerriman", "key": "emerriman", "displayName": "Eric Merriman ", "active": true, "timeZone": "America/Los_Angeles" }, "body": "Closing as invalid. If incorrect, please reopen.", "updateAuthor": { "name": "emerriman", "key": "emerriman", "displayName": "Eric Merriman ", "active": true, "timeZone": "America/Los_Angeles" }, "created": "2018-08-06T17:37:03.000+0000", "updated": "2018-08-06T17:37:03.000+0000" } ], "maxResults": 4, "total": 4, "startAt": 0 } } }