Uploaded image for project: 'Titanium SDK/CLI'
  1. Titanium SDK/CLI
  2. TIMOB-7254

Android: Intent - return EXTRA_STREAM data as blob




      Using the current array of functions available to Ti.Android.Intent, there is no way to get binary data from a Ti.Android.EXTRA_STREAM extra. Ti.Android.EXTRA_STREAM wants to return an Android URI, which we have no means to return. In addition, URIs will be tough to resolve on the developer's end unless they are just passing them to another Intent.

      For example, a very common case is that a developer would like to use an Android Intent Filter in their Titanium app to be able to receive SEND Intents for things like images. Often a user will want to show that image in their Titanium app immediately. A URI isn't going to do them much good, unresolved. To that end a Ti.Android.Intent.getBlobExtra() function would be extremely useful.

      Proposed Usage

      var win = Ti.UI.createWindow({
      	backgroundColor: '#fff',
      	fullscreen: false,
      	exitOnClose: true
      win.addEventListener('open', function(e) {
      	var intent = Ti.Android.currentActivity.getIntent();
      	var iname = Ti.Android.EXTRA_STREAM;
      	if (intent && intent.hasExtra(iname)) {
      		// Create ImageView from TiBlob
      		var blob = intent.getBlobExtra(iname);	
      			image: blob,
      			height: 300,
      			width: 300,
      			left: 0,
      			top: 0
      	} else {
      		Ti.API.info('No extra named "' + iname + '" found in Intent');

      As this code reacts to an Intent, it will require that an Intent Filter is setup to receive it. Use the filter below in a custom AndroidManifest.xml. Make sure this Intent Filter is inside the main activity.

          <action android:name="android.intent.action.SEND" />
          <category android:name="android.intent.category.DEFAULT" />
          <data android:mimeType="image/*" />

      To test, long press on an image in the android gallery and select "share". This test code should then appear as an option in the Intent Filter list.

      Additional Notes

      • TIMOB-3448 is a very similar issue. That issue requests access to the underlying URI to be able to pass it to another Intent. What I am proposing would be to take it a step further by resolving the URI behind the scenes and returning the data as a blob.
      • TIMOB-7249 should be addressed before, or shortly after, this feature request is included in titanium_mobile. TIMOB-7249 shows that the getData(), getAction(), and getType() functions do not return the appropriate values. This will be a problem for any app that uses an Intent Filter that attempts to handle more than one type of data.




            • Assignee:
              billdawson Bill Dawson
              tlukasavage Tony Lukasavage
            • Watchers:
              5 Start watching this issue


              • Created:

                Git Source Code