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

Android: Intent - return EXTRA_STREAM data as blob

    Details

      Description

      Problem

      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);	
      		win.add(Ti.UI.createImageView({
      			image: blob,
      			height: 300,
      			width: 300,
      			left: 0,
      			top: 0
      		}));
      	} else {
      		Ti.API.info('No extra named "' + iname + '" found in Intent');
      	}
      });
      win.open();
      

      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.

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

      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.

        Attachments

          Activity

            People

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

              Dates

              • Created:
                Updated:
                Resolved:

                Git Source Code