Titanium JIRA Archive
Titanium SDK/CLI (TIMOB)

[TIMOB-3448] Android: cannot retrieve EXTRA_STREAM from Intent (no getUriExtra)

GitHub Issuen/a
TypeBug
PriorityLow
StatusClosed
ResolutionInvalid
Resolution Date2017-06-08T18:11:04.000+0000
Affected Version/sn/a
Fix Version/sn/a
ComponentsAndroid
Labelsandroid, extras, intent, intents
ReporterBrion Vibber
AssigneeIngo Muschenetz
Created2011-04-15T03:45:17.000+0000
Updated2017-06-08T18:11:04.000+0000

Description

I'm using Titanium Mobile 1.5/1.6's support for native Android intents and activities to let our StatusNet Mobile app accept text and image attachments from other social networking apps and the system Gallery and Camera apps.

Unfortunately I'm having some trouble accepting images, which are attached as a Uri object in the EXTRA_STREAM extra field. Calling intent.getStringExtra(Ti.Android.EXTRA_STREAM) fails, because the returned object is a Uri, not a string:

W/Bundle  ( 1569): Key android.intent.extra.STREAM expected String but value was a android.net.Uri$HierarchicalUri.  The default value <null> was returned.
W/Bundle  ( 1569): Attempt to cast generated internal exception:
W/Bundle  ( 1569): java.lang.ClassCastException: android.net.Uri$HierarchicalUri
W/Bundle  ( 1569):  at android.os.Bundle.getString(Bundle.java:1040)
W/Bundle  ( 1569):  at android.content.Intent.getStringExtra(Intent.java:3368)
W/Bundle  ( 1569):  at org.appcelerator.titanium.proxy.IntentProxy.getStringExtra(IntentProxy.java:239)
W/Bundle  ( 1569):  at org.appcelerator.titanium.proxy.IntentProxyBindingGen$3.invoke(IntentProxyBindingGen.java:187)
W/Bundle  ( 1569):  at org.appcelerator.kroll.KrollMethod.call(KrollMethod.java:51)
W/Bundle  ( 1569):  at org.mozilla.javascript.Interpreter.interpretLoop(Interpreter.java:1711)
W/Bundle  ( 1569):  at org.mozilla.javascript.Interpreter.interpret(Interpreter.java:854)
W/Bundle  ( 1569):  at org.mozilla.javascript.InterpretedFunction.call(InterpretedFunction.java:164)
W/Bundle  ( 1569):  at org.mozilla.javascript.ContextFactory.doTopCall(ContextFactory.java:426)
W/Bundle  ( 1569):  at org.mozilla.javascript.ScriptRuntime.doTopCall(ScriptRuntime.java:3161)
W/Bundle  ( 1569):  at org.mozilla.javascript.InterpretedFunction.call(InterpretedFunction.java:162)
W/Bundle  ( 1569):  at org.appcelerator.titanium.kroll.KrollCallback.callSync(KrollCallback.java:139)
W/Bundle  ( 1569):  at org.appcelerator.titanium.kroll.KrollCallback.callSync(KrollCallback.java:113)
W/Bundle  ( 1569):  at org.appcelerator.titanium.kroll.KrollCallback.callSync(KrollCallback.java:108)
W/Bundle  ( 1569):  at org.appcelerator.titanium.kroll.KrollCallback.callSync(KrollCallback.java:104)
W/Bundle  ( 1569):  at org.appcelerator.kroll.KrollProxy.fireSingleEvent(KrollProxy.java:629)
W/Bundle  ( 1569):  at org.appcelerator.kroll.KrollEventManager$KrollListener.invoke(KrollEventManager.java:143)
W/Bundle  ( 1569):  at org.appcelerator.kroll.KrollEventManager.dispatchEvent(KrollEventManager.java:273)
W/Bundle  ( 1569):  at org.appcelerator.kroll.KrollProxy.fireSyncEvent(KrollProxy.java:600)
W/Bundle  ( 1569):  at org.appcelerator.titanium.TiBaseActivity.onCreate(TiBaseActivity.java:294)
W/Bundle  ( 1569):  at org.appcelerator.titanium.TiLaunchActivity.onCreate(TiLaunchActivity.java:97)
W/Bundle  ( 1569):  at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
W/Bundle  ( 1569):  at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2627)
W/Bundle  ( 1569):  at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2679)
W/Bundle  ( 1569):  at android.app.ActivityThread.access$2300(ActivityThread.java:125)
W/Bundle  ( 1569):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2033)
W/Bundle  ( 1569):  at android.os.Handler.dispatchMessage(Handler.java:99)
W/Bundle  ( 1569):  at android.os.Looper.loop(Looper.java:123)
W/Bundle  ( 1569):  at android.app.ActivityThread.main(ActivityThread.java:4627)
W/Bundle  ( 1569):  at java.lang.reflect.Method.invokeNative(Native Method)
W/Bundle  ( 1569):  at java.lang.reflect.Method.invoke(Method.java:521)
W/Bundle  ( 1569):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
W/Bundle  ( 1569):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
W/Bundle  ( 1569):  at dalvik.system.NativeStart.main(Native Method)

I notice in ticket #2587, someone encountered the same problem when creating such intents to send to other applications, and an Intent.putUriExtra() was added to accommodate it, converting from a string parameter to a Uri.

It looks like it would be helpful to add an Intent.getUriExtra(), or else tweak things such that there's some other clear way to retrieve it.

Comments

  1. Lee Morris 2017-06-08

    Closing ticket due to time passed and lack on input for the past 6 years. Any problems, please open a new ticket.

JSON Source