Titanium Mobile
  1. Titanium Mobile
  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.
      1. console_logs.txt
        17 kB
        Deepti Pandey
      1. Screenshot_TIMOB-7254.png
        266 kB

        Activity

        Hide
        Tony Lukasavage added a comment -

        I'm working on a pull request for this feature now. Just needed to create a corresponding Jira ticket first.

        Show
        Tony Lukasavage added a comment - I'm working on a pull request for this feature now. Just needed to create a corresponding Jira ticket first.
        Hide
        Bill Dawson added a comment - - edited

        Additional Testing Notes

        Here's how to get this to work (the part about the additions to the Android Manifest might be a little confusing).

        • Create an app with the code Tony put in above.
        • After you create the app, create a platform/android folder.
        • Copy build/android/AndroidManifest.xml to platform/android/AndroidManifest.xml. This makes a custom AndroidManifest.xml.
        • Open platform/android/AndroidManifest.xml.
        • Find the section for the default activity. It will look like this (though the name might be different in your case):

        <activity android:name=".Timob7254Activity"
            android:label="timob7254" android:theme="@style/Theme.Titanium"
            android:configChanges="keyboardHidden|orientation">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
        </activity>
        

        • See that "intent-filter" section? You'll want to make a second one right below it, using the intent-filter Tony provided above. So in my example it will end up looking like:

        <activity android:name=".Timob7254Activity"
            android:label="timob7254" android:theme="@style/Theme.Titanium"
            android:configChanges="keyboardHidden|orientation">
        <intent-filter>
            <action android:name="android.intent.action.MAIN" />
            <category android:name="android.intent.category.LAUNCHER" />
        </intent-filter>
        <intent-filter>
            <action android:name="android.intent.action.SEND" />
            <category android:name="android.intent.category.DEFAULT" />
            <data android:mimeType="image/*" />
        </intent-filter>
        </activity>
        

        • Save that file.
        • Build and install the app on a device/emulator that has some photos in its photo gallery.
        • Go to the device's photo gallery and long-press a photo, then select "Share" (or "Send" or whatever).
        • You'll see a list of installed applications that are able to share/send a photo. The app you just created should be listed among them – choose it.
        • The app should open and display the photo.

        Show
        Bill Dawson added a comment - - edited Additional Testing Notes Here's how to get this to work (the part about the additions to the Android Manifest might be a little confusing). Create an app with the code Tony put in above. After you create the app, create a platform/android folder. Copy build/android/AndroidManifest.xml to platform/android/AndroidManifest.xml. This makes a custom AndroidManifest.xml. Open platform/android/AndroidManifest.xml. Find the section for the default activity. It will look like this (though the name might be different in your case): <activity android:name=".Timob7254Activity" android:label="timob7254" android:theme="@style/Theme.Titanium" android:configChanges="keyboardHidden|orientation"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> See that "intent-filter" section? You'll want to make a second one right below it, using the intent-filter Tony provided above. So in my example it will end up looking like: <activity android:name=".Timob7254Activity" android:label="timob7254" android:theme="@style/Theme.Titanium" android:configChanges="keyboardHidden|orientation"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> <intent-filter> <action android:name="android.intent.action.SEND" /> <category android:name="android.intent.category.DEFAULT" /> <data android:mimeType="image/*" /> </intent-filter> </activity> Save that file. Build and install the app on a device/emulator that has some photos in its photo gallery. Go to the device's photo gallery and long-press a photo, then select "Share" (or "Send" or whatever). You'll see a list of installed applications that are able to share/send a photo. The app you just created should be listed among them – choose it. The app should open and display the photo.
        Hide
        Natalie Huynh added a comment -

        Tested with Nexus One 2.2.2 with 2.1.0.v20120612170248

        Show
        Natalie Huynh added a comment - Tested with Nexus One 2.2.2 with 2.1.0.v20120612170248
        Hide
        Smbat Yeranyan added a comment -

        I'm having a bit of a trouble with this function, I did exactly as followed but my App throws an exception saying Uncaught TypeError: Object #<intent> has no method 'getBlobExtra'

        I suppose I have to reference a library in Titanium, but I'm having a difficult time understanding where and what to to reference. I even have SDK 2.1.0 installed. I simply just wanted to fetch my image path from the gallery so that I can upload it but that did not work traditionally and through hours of reading I ended up here.

        Thanks in advance

        Show
        Smbat Yeranyan added a comment - I'm having a bit of a trouble with this function, I did exactly as followed but my App throws an exception saying Uncaught TypeError: Object #<intent> has no method 'getBlobExtra' I suppose I have to reference a library in Titanium, but I'm having a difficult time understanding where and what to to reference. I even have SDK 2.1.0 installed. I simply just wanted to fetch my image path from the gallery so that I can upload it but that did not work traditionally and through hours of reading I ended up here. Thanks in advance
        Hide
        Deepti Pandey added a comment - - edited

        Reopening this ticket as application is getting crashed on launching.
        This is a regression . The test app is working fine using 3.2.3.GA build.
        Configurations used:
        Mac :10.9.2
        Appcelerator Studio, build:3.3.0.201405211748
        SDK - 3.3.0.v20140522144936
        acs-1.0.14
        alloy@1.4.0-alpha3
        npm-1.3.2
        titanium@3.3.0-alpha5
        titanium-code-processor-1.1.1
        Xcode :5.1.1
        Devices Used:
        Nexus 4 (4.1.1)

        Please find attached log (console_logs.txt) and screenshot.

        Show
        Deepti Pandey added a comment - - edited Reopening this ticket as application is getting crashed on launching. This is a regression . The test app is working fine using 3.2.3.GA build. Configurations used: Mac :10.9.2 Appcelerator Studio, build:3.3.0.201405211748 SDK - 3.3.0.v20140522144936 acs-1.0.14 alloy@1.4.0-alpha3 npm-1.3.2 titanium@3.3.0-alpha5 titanium-code-processor-1.1.1 Xcode :5.1.1 Devices Used: Nexus 4 (4.1.1) Please find attached log (console_logs.txt) and screenshot.
        Hide
        Lokesh Choudhary added a comment -

        Tried to reproduce but the issues is not reproducible.

        Followed steps by Bill Dawson & the app does not crash. Selecting the app to share the pic from the gallery shows the shared pic in the app.

        Environment:
        Appc Studio : 3.3.0.201405211748
        Ti SDK : 3.3.0.v20140523120121
        Mac OSX : 10.8.5
        Alloy : 1.4.0-alpha4
        CLI - 3.3.0-alpha5
        Code Processor: 1.1.1
        Samsung Galaxy S4 - android 4.2.2
        Sony Xperia - android 2.3.7
        Samsung S3 - android 4.0.4

        Show
        Lokesh Choudhary added a comment - Tried to reproduce but the issues is not reproducible. Followed steps by Bill Dawson & the app does not crash. Selecting the app to share the pic from the gallery shows the shared pic in the app. Environment: Appc Studio : 3.3.0.201405211748 Ti SDK : 3.3.0.v20140523120121 Mac OSX : 10.8.5 Alloy : 1.4.0-alpha4 CLI - 3.3.0-alpha5 Code Processor: 1.1.1 Samsung Galaxy S4 - android 4.2.2 Sony Xperia - android 2.3.7 Samsung S3 - android 4.0.4
        Hide
        Eric Merriman added a comment -

        Deepti Pandey We are unable to reproduce. Can you attempt?

        Show
        Eric Merriman added a comment - Deepti Pandey We are unable to reproduce. Can you attempt?
        Hide
        Priya Agarwal added a comment -

        Closing the issue since it is not reproducible.

        Followed steps by Bill Dawson & the app does not crash. Selecting the app to share the pic from the gallery shows the shared pic in the app.

        But on importing and using the app from titanium_mobile_tests_internal/FeatureTest/Android/TIMOB-7254 app crashes.Hence test app needs modification.

        Verified with Environment:
        Appc-Studio:3.3.0.201405271647
        sdk:3.3.0.v20140602174112
        acs:1.0.14
        alloy:1.4.0-beta
        npm:1.3.2
        titanium:3.3.0-beta2
        titanium-code-processor:1.1.1
        xcode:5.1.1
        Device:Nexus7(v4.4.2)
        OS:Maverick(10.9.2)

        Hence closing the issue.

        Show
        Priya Agarwal added a comment - Closing the issue since it is not reproducible. Followed steps by Bill Dawson & the app does not crash. Selecting the app to share the pic from the gallery shows the shared pic in the app. But on importing and using the app from titanium_mobile_tests_internal/FeatureTest/Android/ TIMOB-7254 app crashes.Hence test app needs modification. Verified with Environment: Appc-Studio:3.3.0.201405271647 sdk:3.3.0.v20140602174112 acs:1.0.14 alloy:1.4.0-beta npm:1.3.2 titanium:3.3.0-beta2 titanium-code-processor:1.1.1 xcode:5.1.1 Device:Nexus7(v4.4.2) OS:Maverick(10.9.2) Hence closing the issue.
        Hide
        Lokesh Choudhary added a comment -

        Modifications made to the test app & pushed to repo.

        Show
        Lokesh Choudhary added a comment - Modifications made to the test app & pushed to repo.

          People

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

            Dates

            • Created:
              Updated:
              Resolved:

              Development

                Poker Sessions

                This issue is currently not assigned to any Poker Session.