{ "id": "81871", "key": "TIMOB-5842", "fields": { "issuetype": { "id": "2", "description": "A new feature of the product, which has yet to be developed.", "name": "New Feature", "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": null, "resolutiondate": null, "created": "2011-10-24T09:45:55.000+0000", "priority": { "name": "Medium", "id": "3" }, "labels": [ "core" ], "versions": [ { "id": "11971", "description": "iOS5 and select Android fixes", "name": "Release 1.7.3", "archived": true, "released": true, "releaseDate": "2011-10-18" } ], "issuelinks": [], "assignee": null, "updated": "2019-04-03T09:39:23.000+0000", "status": { "description": "The issue is open and ready for the assignee to start work on it.", "name": "Open", "id": "1", "statusCategory": { "id": 2, "key": "new", "colorName": "blue-gray", "name": "To Do" } }, "components": [ { "id": "10202", "name": "Android", "description": "Android Platform" } ], "description": "Many Android Intents allow extras that require specific types. In some instances when the Titanium Android code can't convert these types, defaults will be used resulting in unexpected behavior. For example, the intent below expects integers for the first 4 extra values, but is automatically casting them as doubles on the Android side. This is causing all of those extras to default to 0.\r\n\r\n{code:lang=javascript}\r\nvar intent = Ti.Android.createIntent({\r\n action: \"com.android.camera.action.CROP\",\r\n data: 'file:///mnt/sdcard/download/images.jpeg',\r\n type: 'image/*'\r\n });\r\n intent.putExtra(\"crop\", \"true\");\r\n intent.putExtra(\"aspectX\", 1);\r\n intent.putExtra(\"aspectY\", 1);\r\n intent.putExtra(\"outputX\", 60);\r\n intent.putExtra(\"outputY\", 80);\r\n intent.putExtra(\"return-data\", true);\r\n{code}\r\n\r\nWhen the above intent is run from an activity, the following can be found in the log:\r\n\r\n{code}\r\n10-24 16:08:18.217: W/Bundle(945): Key outputX expected Integer but value was a java.lang.Double. The default value 0 was returned.\r\n10-24 16:08:18.227: W/Bundle(945): Attempt to cast generated internal exception:\r\n10-24 16:08:18.227: W/Bundle(945): java.lang.ClassCastException: java.lang.Double\r\n10-24 16:08:18.227: W/Bundle(945): at android.os.Bundle.getInt(Bundle.java:918)\r\n10-24 16:08:18.227: W/Bundle(945): at android.os.Bundle.getInt(Bundle.java:901)\r\n10-24 16:08:18.227: W/Bundle(945): at com.android.camera.CropImage.onCreate(CropImage.java:124)\r\n10-24 16:08:18.227: W/Bundle(945): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)\r\n10-24 16:08:18.227: W/Bundle(945): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)\r\n10-24 16:08:18.227: W/Bundle(945): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)\r\n10-24 16:08:18.227: W/Bundle(945): at android.app.ActivityThread.access$2300(ActivityThread.java:125)\r\n10-24 16:08:18.227: W/Bundle(945): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)\r\n10-24 16:08:18.227: W/Bundle(945): at android.os.Handler.dispatchMessage(Handler.java:99)\r\n10-24 16:08:18.227: W/Bundle(945): at android.os.Looper.loop(Looper.java:123)\r\n10-24 16:08:18.227: W/Bundle(945): at android.app.ActivityThread.main(ActivityThread.java:4627)\r\n10-24 16:08:18.227: W/Bundle(945): at java.lang.reflect.Method.invokeNative(Native Method)\r\n10-24 16:08:18.227: W/Bundle(945): at java.lang.reflect.Method.invoke(Method.java:521)\r\n10-24 16:08:18.227: W/Bundle(945): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)\r\n10-24 16:08:18.227: W/Bundle(945): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)\r\n10-24 16:08:18.227: W/Bundle(945): at dalvik.system.NativeStart.main(Native Method)\r\n{code}\r\n\r\nTo remedy the situation, we should likely allow developers to specify a type when declaring extras, or create convenience functions for all available types that can be passed to an Intent. So {{Titanium.Android.Intent.putExtra}} should, in addition to the current {{name}} and {{value}} parameters, also take a {{type}} parameter that can be used to cast the value on the Android side. Alternatively, or complimentary, There could also be extra convenience functions like {{putStringExtra}}, {{putIntExtra}}, {{putDoubleExtra}}, etc...\r\n\r\nFor reference, this ticket is a result of the following Q&A question: [http://developer.appcelerator.com/question/127302/how-do-i-pass-integers-to-intents|http://developer.appcelerator.com/question/127302/how-do-i-pass-integers-to-intents]", "attachment": [], "flagged": false, "summary": "Android: Allow type specifier for Android Intent extras", "creator": { "name": "tlukasavage", "key": "tlukasavage", "displayName": "Tony Lukasavage", "active": true, "timeZone": "America/Los_Angeles" }, "subtasks": [], "reporter": { "name": "tlukasavage", "key": "tlukasavage", "displayName": "Tony Lukasavage", "active": true, "timeZone": "America/Los_Angeles" }, "environment": "Titanium mobile SDK 1.7.3", "comment": { "comments": [ { "id": "196216", "author": { "name": "karl.astrom", "key": "karl.astrom", "displayName": "Karl Åström", "active": true, "timeZone": "America/Los_Angeles" }, "body": "Six months since last update on this. It's high priority. Can we get a statement on this? Forgotten? In the works?", "updateAuthor": { "name": "karl.astrom", "key": "karl.astrom", "displayName": "Karl Åström", "active": true, "timeZone": "America/Los_Angeles" }, "created": "2012-05-28T01:05:24.000+0000", "updated": "2012-05-28T01:05:24.000+0000" }, { "id": "202013", "author": { "name": "zman0900", "key": "zman0900", "displayName": "Dan Ziemba", "active": true, "timeZone": "America/New_York" }, "body": "I agree that this would be a useful feature. I was unable to properly set the begin and end times when launching an intent to insert a new calendar event to content://com.android.calendar/events because the 'beginTime' and 'endTime' extra keys were expecting Long but being given Integer.\r\n\r\nI've created a module that implements putLongExtra and it should be simple to add other similar methods. So until this feature is added, here's the module: https://github.com/zman0900/titanium-improvedintent", "updateAuthor": { "name": "zman0900", "key": "zman0900", "displayName": "Dan Ziemba", "active": true, "timeZone": "America/New_York" }, "created": "2012-07-07T16:19:51.000+0000", "updated": "2012-07-07T16:19:51.000+0000" }, { "id": "447444", "author": { "name": "gdrusch", "key": "gdrusch", "displayName": "Gautier Drusch", "active": true, "timeZone": "Europe/Paris" }, "body": "Is there a plan to resolve this issue? We need to add a calendar Intent to our app but when we create an Intent from Ti.Android.createIntent and then set the beginTime like that:\r\n{code:java}\r\nintent.putExtra(\"beginTime\", 1554276167093)\r\n{code}\r\n the extra is passed as a Double instead of Long to the Android SDK.", "updateAuthor": { "name": "gdrusch", "key": "gdrusch", "displayName": "Gautier Drusch", "active": true, "timeZone": "Europe/Paris" }, "created": "2019-04-03T09:39:23.000+0000", "updated": "2019-04-03T09:39:23.000+0000" } ], "maxResults": 3, "total": 3, "startAt": 0 } } }